mardi 7 février 2017

How should i implement this database-heavy function?

i'm working on a django application, i'm very new to django and to coding as a whole.

I'm working on a voting app where people first submit images and then they get displayed random images to vote on, i'm currently implementing a duplicate report function, where the person chooses two submission displayed, then they return to the database as a duplicate report object, here's how i want it to work:

First, the person reports the two duplicates in the template.

Then, the two duplicates return as a duplicate report object, this is what the table looks like in my models.py file:

class RepReport(models.Model):
count = models.IntegerField()
oldersub = models.ForeignKey('Submission', on_delete=models.CASCADE, related_name='older_sub')
newersub = models.ForeignKey('Submission', on_delete=models.CASCADE, related_name='newer_sub')

Then, in the view, if there are no RepReport rows with the selected combination, a new RepReport row is created, containing the combination and with the starting count amount of 1, if there already is one with the combination, the count of that row is increased by 1.

After the count of a given RepReport row reaches 5, the submission that was sent the lates gets deleted, and the oldes one's vote count gets converted to the sum of their vote counts divided by 3, like this.

def duplicatekill(oldersub, newersub):
   sum = oldersub.voteCount + newersub.voteCount
   oldersub.voteCount = sum/3
   newersub.delete()
   oldersub.save()

I also want oldersub to inherit any other RepReports newersub paired with, which would eventually cause a chain reaction of several duplicatekill functions happening from one report, that's why i'm here, i can't think of a server efficient way to do that whole amount of work and handling voting at the same time.

I haven't made up my mind on which SQL system i'll be using either.




Aucun commentaire:

Enregistrer un commentaire