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 done #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

RainaJain5
Copy link
Member

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.

Comment on lines +150 to +155
Calc_Rate=BookRating.objects.filter(book=books)
book_rate = 0
for r in Calc_Rate:
book_rate += r.rating
book_rate /= len(Calc_Rate)
book_rate = round(book_rate,2)
Copy link
Member

Choose a reason for hiding this comment

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

A very clean and more Django-ish way for this could be, using aggregate functions in Django ORM.

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

Comment on lines +37 to +41
rating = models.IntegerField(default=0, validators=[
MaxValueValidator(10),
MinValueValidator(0)
])
user = models.ForeignKey(User, related_name='user', null=True, blank=True, on_delete=models.SET_NULL)
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 +139 to +143
books = Book.objects.get(id=book_id)
rating1 = BookRating.objects.filter(book=books, user=request.user)

if len(rating1)==0:
new_rating = BookRating(book=books, user=request.user, rating=book_rate)
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 get_or_create could be used here for better code clarity.

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