0

I am trying to get rate of the user who has written the comment.

this is the scenario:

I hold the comment about Something in my hand, I hold the user in my hand who wrote this comment Something. Now I need to know the rate which is given by the user to this Something.

these are my models:

class Rate(models.Model):
  of_user_r = models.ForeignKey(User)
  of_something_r = models.ForeignKey(Something)
  rate = models.IntegerField()

class Comment(models.Model):
  of_user_c = models.ForeignKey(User)
  of_something_c = models.ForeignKey(Something)

i did: {{comment.of_user_c.of_user_r.rate}}, but I getting nothing in template. this is the vusual:

enter image description here

I need the rate of this Something which is given by this User.

doniyor
  • 36,596
  • 57
  • 175
  • 260

1 Answers1

1

Yes, your attempt doesn't work because the relationship from User to Rate is backwards. This means you can't do that query directly in the template: you'd need a model method or a template filter that accepts arguments. The basic query syntax would be:

Rate.objects.filter(user=comment.user)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895