Changed Upvote and Downvote Functionality to be unique

This commit is contained in:
2024-04-12 18:00:52 -04:00
parent 5d4551e4fa
commit af9340c54f
3 changed files with 48 additions and 4 deletions

View File

@@ -58,7 +58,13 @@ class File(models.Model):
Course, on_delete=models.SET_NULL, null=True, related_name="files"
)
created_at = models.DateTimeField(auto_now_add=True)
points = models.IntegerField(default=0, blank=False)
upvotes = models.ManyToManyField(PeerUser, related_name="upvoted_file")
downvotes = models.ManyToManyField(PeerUser, related_name="downvoted_file")
@property
def points(self):
return self.upvotes.count() - self.downvotes.count()
def __str__(self):
return self.filename