Tuesday, May 8, 2012

limit row in change view

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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate