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

All Tasks Completed #16

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

Conversation

it-is-skywalkerl
Copy link
Member

@it-is-skywalkerl it-is-skywalkerl commented Jul 23, 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 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']
Copy link
Member

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)])
Copy link
Member

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.

Comment on lines +144 to +147
try:
previous_user_rating = BookRating.objects.get(book=book, user=user)
except ObjectDoesNotExist:
previous_user_rating = BookRating()
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 get_or_create here for better code clarity.

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

Successfully merging this pull request may close these issues.

2 participants