How to get related model in template?
django, django-models, django-templates
Solution
Try it:
{{ m.model_2_set.all }}
You can change model_2_set if you define the related name. There is not changes if this is in template or in a view
Problem
I have models: ``` class Model_1(models.Model): name = ... [...] class Model_2(models.Model): model_1 = models.ForeignKey(Model_1) ``` and now I get model_1 objects in view, and in template I want to get model_2: ``` {% for m in models_1 %} {{ m.model_2 }} ????? {% endfor %} ``` How to do it?