Handling django admin query params automatic redirects

28 views
Skip to first unread message

alonn

unread,
Dec 11, 2023, 2:43:33 AM12/11/23
to PyWeb-IL
I need to pass some data to a custom django admin view (rendering a graph)
I want to pass it through queryparms, my problem that if I pass any queryparam which isn't a model attribute I get redirected to ...path_to_admin/model_name/?e=1
How can I disable this behavior for the model? 

Thanks! 

alonn

unread,
Dec 11, 2023, 2:52:51 AM12/11/23
to PyWeb-IL
I understand It's probably something with get_urls, but missing something here

Meir Kriheli

unread,
Dec 11, 2023, 10:29:03 AM12/11/23
to pywe...@googlegroups.com
Just an idea: Did you try popping the extra params in something like get_queryset?

--
You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyweb-il+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyweb-il/19173d25-88ad-49db-8bb8-8b1beaec0356n%40googlegroups.com.


--

Shai Berger

unread,
Dec 13, 2023, 3:03:11 AM12/13/23
to alonn, pywe...@googlegroups.com
On Sun, 10 Dec 2023 23:52:50 -0800 (PST)
alonn <alon...@gmail.com> wrote:

> I understand It's probably something with get_urls, but missing
> something here
>

This sounds like handling by a non-custom view. How did you define the
custom view?

One thing that seems particularly likely is that you add your custom
URL after, instead of before, the regular URLs.

See the second note box here:
https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls

alonn

unread,
Dec 17, 2023, 3:09:53 AM12/17/23
to PyWeb-IL
Follow up, after diving into this, I've found out that the Changeset class inside the changeview has a method causing this error. So I can override the changeset class and the changeview method of the admin model class and it would work. 
I also found out that a far easier and probably more "djangoish" solution is just a add an admin filter with those query params, and not use them to filter the queryset. thus the whole inner django machinery treats those params as legit as they are tied to  a "filter" :) 
Thanks for the pointers ! 
Reply all
Reply to author
Forward
0 new messages