-
Notifications
You must be signed in to change notification settings - Fork 41
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 Stages completed #15
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 🎉 . Your submission is evaluated.
book_reviewed = models.ForeignKey(Book, on_delete=models.CASCADE) | ||
rating = models.IntegerField( | ||
default=1, | ||
validators=[MaxValueValidator(10), MinValueValidator(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.
Good use of validators in Django.
book_id = request.POST.get('bid') | ||
rateing = float(request.POST.get('brate')) | ||
list_book = Review.objects.filter(book_reviewed=Book.objects.get(id__exact=book_id)) | ||
list_user_book = Review.objects.filter(Q(book_reviewed=Book.objects.get(id__exact=book_id)) & Q(reviewer=request.user)) |
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.
While this is not wrong but Q
is not needed for such simple queries. You can write even very much complex queries without using Q
.
c.save() | ||
b = Book.objects.get(id__exact=book_id) | ||
previous_rating_of_book = b.rating | ||
new_rating = ((previous_rating_of_book*len(list_book))-previous_rating_by_user+rateing)/len(list_book) |
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 Django-ish way for this would be using aggregate funtion in Django ORM:
Review.objects.filter(book__pk=book_id).aggregate(Avg('rating'))['rating__avg']
CSoC Task 2 Submission
I have completed the following tasks