-
Notifications
You must be signed in to change notification settings - Fork 42
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
All Tasks Completed #16
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 task 🎉 . You subsmission has been evaluated.
previous_user_rating.user = user | ||
previous_user_rating.rating = new_rating | ||
previous_user_rating.save() | ||
book.rating = BookRating.objects.filter(book=book).aggregate(rating=Avg('rating'))['rating'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of aggregate function here 👏🏻 .
class BookRating(models.Model): | ||
book = models.ForeignKey(Book, on_delete=models.CASCADE) | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
rating = models.IntegerField(default=None, validators=[MinValueValidator(0), MaxValueValidator(10)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of validators here.
try: | ||
previous_user_rating = BookRating.objects.get(book=book, user=user) | ||
except ObjectDoesNotExist: | ||
previous_user_rating = BookRating() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use get_or_create
here for better code clarity.
CSoC Task 2 Submission
I have completed the following tasks