Answers for "get related values in dajngo template"

Go
0

get related values in dajngo template

#Model
class Forum(models.Model):
	...
class ForumFront(models.Model):
    forum = models.ForeignKey(Forum, default=None)
    post_count = models.IntegerField(default=0)
    topic_count = models.IntegerField(default=0)
    
#Template
{{ forum }}
<ul>
{% for x in forum.forumfront_set.all %}
    <li>{{ x.topic_count }}, {{ x.post_count }}</li>
{% endfor %}
</ul>
Posted by: Guest on December-06-2020

Browse Popular Code Answers by Language