-
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
Completed The Tasks!!! #4
base: master
Are you sure you want to change the base?
Completed The Tasks!!! #4
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 aassignment 🎉 . Your submission is evaluated.
sum=0.0 | ||
for i in range(len(bookratings)): | ||
sum=sum+bookratings[i].rating | ||
book.rating=round((float)(sum/len(bookratings)), 1) |
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.
This is correct but a more clean and Django-ish way for this could be (with looping):
book.rating = BookRating.objects.filter(book__pk=book_id).aggregate(Avg('rating'))['rating__avg']
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.
Ok I'll make sure to use these functions from next time.
book = models.ForeignKey(Book, on_delete=models.CASCADE) | ||
rater = models.CharField(max_length=122) | ||
rated = models.BooleanField(default = False) | ||
rating = models.SmallIntegerField(default=0) |
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 MinValueValidator
, `MaxValueValidator on this field to have database level rules for it.
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.
Ok I'll take care of this from now onwards.
CSoC Task 2 Submission
I have completed the following tasks