Let `ListFilter` inherit from `RenderableMixin` so that is can render itself

This feature request is more or less related to this one.

The idea is to provide much more flexibility in how ListFilter a rendered. Currently, the admin filters a rendered using the admin_list_filter tag which prevents from defining a custom context. This may be a problem if you want to create a complex JS widget for a custom filter.

If ListFilter was a RenderableMixin, it would be able to render itself the same way Forms do.

There is one problem, though: ListFilter is not aware of its ChangeList container until ListFilter.choices is called. So ListFilter.__init__ signature would have to change.

This could be done the following way:

  • add a changelist parameter to ListFilter.__init__
  • detect if the filter’s __init__ signature features this parameter using inspect.signature
  • if not, flag a deprecation warning and set the attribute after creation
  • when Django 5 is released, remove this code and use only the new signature.

I believe it would help here if you posted a more detailed description of the problem that you are attempting to solve, including a simple example of your identified solution.

My initial reaction to this is that there’s an easier way to do this than what you’re trying to do.

By using a custom template for the filter, we’ve never run into a need to change the rendering process itself.

You can define an attribute for whatever elements you wish, then have your page-level JavaScript attach itself to any elements desired.

Yes, +1. I’m not clear exactly what you’re after.

Pending that: Even if we need a change here, RenderableMixin is internal to django.forms — pulling it out all the way to django.contrib.admin is going to be a little strong. Even if the behaviour is similar, have a more local implementation for admin filters is going to be more coherent and easier to maintain.