Though it doesn’t directly answer your query, you might be interested in this package:
--
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
django-users...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
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/ec0e2d37-9b0f-4623-8f60-c6feeef0eb9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to djang...@googlegroups.com.
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? Explicit is better than implicit. Your example indicates that your primary object is a Device, but your UI dict gives no indication whatsoever that that’s what you want.
If you want to look for related fields in a model, check out the Model _meta API:
https://docs.djangoproject.com/en/1.11/ref/models/meta/
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')
It would seem that you want your UI to pass in the primary model and with all other models how they are related to the primary model.
To post to this group, send email to django...@googlegroups.com.
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/f692aa3a-cc23-4d78-8e3f-16ed30097038%40googlegroups.com.
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?
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')
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: django...@googlegroups.com [mailto:django...@googlegroups.com]
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)
--
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
django-users...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
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.
Is it really that bad? Maybe I’m missing something in your situation.