How to not overwrite existing get parameters

234 views
Skip to first unread message

Jack Vanier

unread,
Feb 27, 2021, 4:29:53 PM2/27/21
to django-filter
I am using django-filter along with django-tables2. I call the ListView page which is using django-tables2 using something like:
http://localhost:8000/APPNAME/?var1='a'&var2='b'&var3='c'
I can then sort the columns in the django table which adds &sort='columnName' to the end of that URL however when I attempt to filter it replaces all my GET params with django-filters own thus I lose access to them which i need to render my table properly. The url turns into:
http://localhost:8000/APPNAME/?home_team__team_name__icontains=&away_team__team_name__icontains=Detr&date__icontains=
However i want to just append the new GET parameters to the list of existing ones so then we can have all 7 in one URL so it would be something along the lines of:
that way django-filter has its data it needs and I have the data I need to render my table.

Carlton Gibson

unread,
Feb 28, 2021, 4:08:03 AM2/28/21
to django...@googlegroups.com
Hi Jack, 

Have a look here: 
DRF provides these two utility methods to adjust query params. 
Do they give you what you need? 

Kind regards, Carlton 


--
You received this message because you are subscribed to the Google Groups "django-filter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-filte...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-filter/1e3bbd8f-9043-45e7-8031-5787971ffdden%40googlegroups.com.

Jack Vanier

unread,
Mar 1, 2021, 7:19:54 PM3/1/21
to django-filter
Hi Carlton

Thanks for the response. Is there no way to do this without using the DRF? I dont currently have it installed because I do not need it as of yet and id prefer not to install it just for this purpose.

Carlton Gibson

unread,
Mar 1, 2021, 11:34:23 PM3/1/21
to django...@googlegroups.com
The functions are only a few lines. You can copy them into your project if you don’t want to install DRF. 

You can customise to exactly what you need, but they show the approach. It’s not so complicated. 

C.

Jack Vanier

unread,
Mar 2, 2021, 9:58:24 PM3/2/21
to django-filter
I am still confused. If you dont want to help me anymore I completely understand since im probably just making a stupid mistake which I understand you dont want to spend your time explaining but im going to put what im confused about anyways just in case someone else stumbles upon this. I dont understand where I could call that function. Does django-filters not set the URL parameters when you hit the submit button? What do I need to override in order to actually add my custom  URL parameters to the URL when I hit filter? From my point of view it looks like when i hit filter django-filter is doing all that "behind the scenes" and i dont really have access to it? I asked this question on stack overflow https://stackoverflow.com/questions/66449897/how-to-get-django-filter-to-not-overwrite-get-params wher I made a simple small testcase in case anyone might know how to help me.

Carlton Gibson

unread,
Mar 3, 2021, 3:47:47 AM3/3/21
to django...@googlegroups.com
Hi Jack. 

I commented on the SO question, linking to a similar one... — maybe that helps. 

I think the bottom line is that you want to include an additional form encoding the extra URL params — SO THAT when the form is submitted those get included too. 

I don’t think this is tricky per se, but it’s not something that’s provided out of the box. 
I think it would make a good addition to django-filter (I don’t often say that :) — if you wanted to hop over to the discussions on the repo we could start a thread, beginning with the SO issues, and the DRF helpers, and then we could look for prior-art (people have done this) before planning a feature. 

Kind regards, Carlton 

Reply all
Reply to author
Forward
0 new messages