Is it really that bad? Maybe I’m missing something in your situation. I use
my own custom page_queryset function. I never got around to looking at the
built-in Django way of doing it. I think there is a generic view that can do
paging.
q = Device.objects.filter(hostname__contains= 'localhost ',
package__name__contains= 'unix ', interface__IP__address__contains= '192')
total_count = q.count()
def page_queryset(qs, page, count_per_page):
"""
:param qs: the queryset or list to slice
:param page: the current page to get records from (1-based)
:param count_per_page: how many items are part of each page
:return: a tuple: the index of the last page, the sliced queryset
"""
slice_begin = (page - 1) * count_per_page
slice_end = slice_begin + count_per_page
if type(qs) == QuerySet:
max_count = qs.count()
else:
max_count = len(qs)
slice_end = slice_end if slice_end < max_count else max_count
last_page = max_count // count_per_page + 1
return last_page, qs[slice_begin:slice_end]
From: [email protected] [mailto:[email protected]] On
Behalf Of Samuel Abels
Sent: Monday, November 6, 2017 2:22 PM
To: Django users
Subject: Re: Equivalent of multi-table JOIN (another post on reverse
select_related)
On Monday, November 6, 2017 at 9:15:09 PM UTC+1, Matthew Pava wrote:
Maybe you are expecting too much from the user interface. Shouldn’t you at
least request from the user what primary object you are looking for?
The primary model is always that one that is closest to "device"; step 2 of the
process already takes this into account and returns the path in the best order,
with the primary model being returned first.
Ultimately, your Django ORM code would look like this for your example, if I
follow your arrows correctly:
Device.objects.filter(hostname__contains= 'localhost ',
package__name__contains= 'unix ', interface__IP__address__contains= '192')
This would perform the right query, but would not provide me with a total. It
would also be impossible to do paging, because slicing the result does not take
into account that the LEFT JOIN multiplies the number of total rows.
-Samuel
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
[email protected]<mailto:[email protected]>.
To post to this group, send email to
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f1c92f41-ce59-47c5-9a82-6af38467a536%40googlegroups.com<https://groups.google.com/d/msgid/django-users/f1c92f41-ce59-47c5-9a82-6af38467a536%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/0220e4a2f3c84809a51c952f60b8b7f9%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.