I have a django model that contains a multi-valued relation, such as,
class MyModel(models.Model):
name = ..
refby = models.ManyToManyField(MyModel2)
..
class MyModel2(..):
name = ..
date = ..
I need to display it in my template so that I can display all mymodel2 objects that reference mymodel. I am currently doing something like the following,
{% for i in mymodel_obj_list %}
{{i.name}}
{% for m in i.refby.all|dictsortreversed:"date"|slice:"3" %}
{{.. }}
{% endfor %}
<div>
{% for n in i.refby.all|dictsortreversed:"date"|slice:"3:15" %}
{{.. }}
{% endfor %}
</div>
{% endfor %}
As the code shows, I want to show only the last 3 objects of mymodel2, sorted in reverse order by date, although the next 12 are loaded.
Is this a very inefficient method? (Given that the results for refby.all can be several 100 seconds, and the total number of results in "mymodel_obj_list" is also 100 seconds - I use paginator there).
, refb ? , ? , , .
:
obj_list = Table.objects.filter(..)
pl = CustomPaginatorClass(obj_list...)
pl mymodel_obj_list.
!