Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed all the tasks! - Atharva Bhatt #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

atharvabhatt200
Copy link

@atharvabhatt200 atharvabhatt200 commented Jul 22, 2021

CSoC Task 2 Submission

I have completed the following tasks

  • Stage 1
  • Stage 2
  • Stage 3
  • Stage 4

Copy link
Member

@m-e-l-u-h-a-n m-e-l-u-h-a-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Work on the assignment 🎉 . Your submission is evaluated.

class RatingSystem(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)
rated_by = models.ForeignKey(User, on_delete=models.CASCADE)
rating = models.SmallIntegerField(default=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use MinValueValidator, MaxValueValidator for this as validators at database level.

Comment on lines +143 to +145
for ratings_multi in RatingSystem.objects.filter(book=book):
totalrating += ratings_multi.rating
book.rating = totalrating/RatingSystem.objects.filter(book=book).count()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is correct a more clean and Django-ish way for doing this could be:

RatingSystem.objects.filter(book__pk=book_id).aggregate(Avg('rating'))['rating__avg']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants