I have models:
class Model_1(models.Model):
name = models.CharField(...
pos = models.IntegerField(...
class Model_2(models.Model):
...
m1 = models.ManyToManyField(Model_1,...
and I print this in template:
{% for m2 in model2 %}
{% for m1 in m2.m1.all %}
{{ m1.name }}
{% endfor %}
{% endfor %}
but I want to print m1.names ordered by ‘pos’ field. How to do it?
in the model you can specify ordering of the objects. More here