Since the related name in the project foreign key is "review" you have to use that keyword for the related query from project, so it should be "self.review.all()" instead of "self.review_set.all()" in your Project methods.
Regards! On Fri, Oct 12, 2018 at 9:25 AM Melissa Malala <melissamal...@gmail.com> wrote: > Getting an error that says "Project object has no attribute review_set" > when trying to get the mean of ratings using Numpy. HTML looks something > like this, what could be the problem? Please have a look below and let us > know what you think: > > > <h5>{{ project.review.count }} reviews ({{ > project.average_design | floatformat }} average rating of design)</h5><h5>{{ > project.review.count }} reviews ({{ > project.average_content | floatformat }} average rating of > content)</h5><h5>{{ project.review.count }} reviews ({{ > project.average_usability | floatformat }} average rating of > usability)</h5>class Project(models.Model): > title = models.TextField(max_length=200, null=True, blank=True, > default="title") > project_image = models.ImageField(upload_to='picture/', null=True, blank=True) > description = models.TextField() > project_url=models.URLField(max_length=250)def average_design(self): > design_ratings = list(map(lambda x: x.design_rating, > self.review_set.all())) > return np.mean(design_ratings) > def average_usability(self): > usability_ratings = list(map(lambda x: x.usability_rating, > self.review_set.all())) > return np.mean(usability_ratings) > def average_content(self): > content_ratings = list(map(lambda x: x.content_rating, > self.review_set.all())) > return np.mean(content_ratings) > > class Review(models.Model): > RATING_CHOICES = ( > (1, '1'), > (2, '2'), > (3, '3'), > (4, '4'), > (5, '5'), > (6, '6'), > (7, '7'), > (8, '8'), > (9, '9'), > (10, '10'), > ) > project = models.ForeignKey(Project, null=True, blank=True, > on_delete=models.CASCADE, related_name="review") > user = models.ForeignKey(User, null=True, blank=True, > on_delete=models.CASCADE, related_name='user') > image = models.ForeignKey(Image, on_delete=models.CASCADE, > related_name="project", null=True, blank=True) > comment = models.TextField() > design_rating = models.IntegerField(choices=RATING_CHOICES, > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei1S2L3bZ%3D2an7SUd2rOVP%3D38fZkNyDdVt1EFim-OxMR_Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.