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

Completed required tasks #2

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

Conversation

Tarun-Arora
Copy link

@Tarun-Arora Tarun-Arora commented Jul 16, 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 🎉. Your submission has been evaluated.

class bookRating(models.Model):
bookName = models.ForeignKey(Book, on_delete=models.CASCADE)
user = models.ForeignKey(User, related_name='user', null=True, blank=True, on_delete=models.SET_NULL)
ratingValue = models.IntegerField(null=True, 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.

Good use of Django validators here 👏🏻 .

Comment on lines +124 to +126
for i in bookallRatings:
value += i.ratingValue
value=value/len(bookallRatings)
Copy link
Member

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 of doing it could be, using aggregate functions provided in Django ORM.

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

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