Django: get count of ForeignKey item in template?
Posted
by AP257
on Stack Overflow
See other posts from Stack Overflow
or by AP257
Published on 2010-04-11T17:11:20Z
Indexed on
2010/04/11
17:13 UTC
Read the original article
Hit count: 252
django
Straightforward question - apologies if it is a duplicate, but I can't find the answer if so.
I have a User model and a Submission model, like this:
class Submission(models.Model):
uploaded_by = models.ForeignKey('User')
class User(models.Model):
name = models.CharField(max_length=250 )
How can I show the number of Submissions made by each user in the template? I've tried {{ user.submission.count }}
, like this:
for user in users:
{{ user.name }} ({{ user.submission.count }} submissions)
but no luck...
© Stack Overflow or respective owner