carltongibson / django-filter

A generic system for filtering Django QuerySets based on user selections
https://django-filter.readthedocs.io/en/main/
Other
4.39k stars 760 forks source link

Allow passing arguments to `.form` #1630

Closed b1rger closed 6 months ago

b1rger commented 7 months ago

Currently the arguments for the form are hardcoded, it would be great if it was possible to add additional arguments, ideally with something like get_form_kwargs https://github.com/carltongibson/django-filter/blob/00e88652d9308c4c6c4e707c3e0d735dd6843dca/django_filters/filterset.py#L252

carltongibson commented 7 months ago

Hi @b1rger

Hmmm 🤔 Likely I don't want to add API here.

You can already override form...

https://github.com/carltongibson/django-filter/blob/00e88652d9308c4c6c4e707c3e0d735dd6843dca/django_filters/filterset.py#L247-L255

If that's Not DRY enough for you, you can return a functools.partial from get_form_class().

It gets to the point where enough hooks are enough.

I hope that makes sense.

b1rger commented 7 months ago

Hmmm 🤔 Likely I don't want to add API here.

No worries! I just thought that get_form_kwargs is a very often used method in Django

You can already override form...

Yes, thats what I'm doing ;)

If that's Not DRY enough for you, you can return a functools.partial from get_form_class().

I'll look into that!

It gets to the point where enough hooks are enough.

I hope that makes sense.

Sure!

carltongibson commented 6 months ago

I think, on reflection, I want to say no to this (for the reasons given). Thanks.