def post in ListView

321 views
Skip to first unread message

bnmng

unread,
Nov 24, 2021, 8:34:04 AM11/24/21
to Django users
Hi everyone,

Is there anything dangerous about this?
class ItemList(ListView):
    model = Item
    def post(self, request, *args, **kwargs):
        self.request.GET = self.request.POST
        return super().get(request, *args, **kwargs)

I want to use this to accept filtering parameters from a form in a list view template. This ListView also has a get_queryset which returns a filtered query based on the parameters

Lalit Suthar

unread,
Nov 24, 2021, 12:12:31 PM11/24/21
to django...@googlegroups.com
you can use `query_params`

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa7a1392-e388-4727-b412-bd1329daa6c4n%40googlegroups.com.

Lalit Suthar

unread,
Nov 24, 2021, 12:14:21 PM11/24/21
to django...@googlegroups.com
oh my bad that is available in django rest framework only

bnmng

unread,
Nov 24, 2021, 4:19:06 PM11/24/21
to Django users
Thanks, though, Lalit. 

I realized I don't event have to do what I was originally doing.  I can just do this:

def post(self, request, *args, **kwargs):
        return super().get(request, *args, **kwargs)
Then the post params are still available to the queryset method
    def get_queryset(self):
        if self.request.POST.get('query_submitted'):
            ... do stuff ...



Lalit Suthar

unread,
Nov 25, 2021, 12:47:24 AM11/25/21
to django...@googlegroups.com
oh cool :D this is looking more pretty 

Reply all
Reply to author
Forward
0 new messages