FAQ
Hello!
I am trying to undestand how to limit visible rows in change view. It seems
to me a common need, but can not find info in django docs.
I am using the admin interface.
So I have one model and his admin is something as:

ordering = ('-datum','krajnjikorisnik','tipimpulse','impulsecijena')

def queryset(self, request):
qs=super(KrajnjiKorisnikImpulseAdmin, self).queryset(request)
qs=qs.filter(bla bla bla)
return qs

With the queryset of above I filter just the needed rows. I have check with
postgre log, and indeed the correct SELECT statement is generated.

Now I want to get just the top x elements.
I continue to get
"Cannot reorder a query once a slice has been taken."
or
"Cannot filter a query once a slice has been taken."

I have tried to change my queryset function to:
1.
def queryset(self, request):
qs=super(KrajnjiKorisnikImpulseAdmin,
self).queryset(request)[0:2]
qs=qs.filter(bla bla bla)
return qs
2. i have treid to manually construct the queryset for testing purpose as:
def queryset(self, request):
qs=KrajnjiKorisnikImpulse.objects.all()[0:2]
return qs
and i have also commented the ordering statement

Both are giving the above errors. Is not limiting the rows a common feature
one might want, or is not relevant since admin views have pages?

Thanks
Nenad

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/t0Y-wdjz4wMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Search Discussions

  • Nenad Cikic at May 9, 2012 at 3:58 pm
    I have managed to solve it by myself so reporting here if anyone is
    interested. I have checked and the sql Log shows statements are generated
    with LIMIT clause (postgre).
    You have to subclass the ChangeList class ass
    class MyChangeList(ChangeList):
    def get_query_set(self):
    return super(MyChangeList, self).get_query_set()[0:2] #here for
    test i am retrieving top 2 rows

    then in models admin:
    def get_changelist(self, request, **kwargs):
    return MyChangeList

    Bye
    Nenad

    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/yYB6SDT17-sJ.
    To post to this group, send email to django-users@googlegroups.com.
    To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedMay 9, '12 at 4:16a
activeMay 9, '12 at 3:58p
posts2
users1
websitedjangoproject.com

1 user in discussion

Nenad Cikic: 2 posts

People

Translate

site design / logo © 2022 Grokbase