+1 on the proposed changes.
Very little extra complexity for something useful.

Would it be more future-proof if the second param was a dict like {“title”:
“Related Tag”}? Maybe, not sure. KISS, YAGNI and all that? I could get
behind either choice.

I would love for this to also work:

class MyStaffFilter(BooleanFieldListFilter):

    title = "By can haz admin"  # no effect :(  overwritten in __init__
>
> @admin.register(User)
> class UserAdmin(UserAdminBase):
>     list_filter = (
>         ("is_staff", MyStaffFilter),
>     )


A problem with taking only this approach is that user (developer) has to
know exactly which class of filter to subclass, which can be a bit tricky
(e.g. RelatedFieldListFilter or RelatedOnlyFieldListFilter?) I’d argue that
benefits for easy development outweigh the added complexity of the PR.

/$.02


On Sun, May 3, 2020 at 12:35 PM Philipp DC <[email protected]> wrote:

> Hey, I recently took over a ticket regarding adding a title option to
> list_filter
> <https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter>and
> I would like to hear your opinion on how the API for this should look like.
>
>
> The idea of this ticket is that you can add the title that is used for the
> filter directly to list_filter if you don't like the default name.
> Currently, the only way to change the title is by creating a subclass of
> FieldListFilter, set the class attribute title of this class and pass it
> as list_filter=[(field, custom_class)]. Especially if the field is a
> foreign key the default name (which is the verbose_name) might not make
> much sense in this context. The pull request currently proposes to add a
> new way by allowing to add a 2-tuple (field, title) to list_filter like
> e.g. ('tags__tag', 'Related Tag')
>
>
> Ticket: https://code.djangoproject.com/ticket/29232
>
> Pull request: https://github.com/django/django/pull/12837
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/b7be92f8-7aac-47e5-abbf-03ef92a98a28%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/b7be92f8-7aac-47e5-abbf-03ef92a98a28%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAM2o%3DwNaP4G9wsEQznvgKTBnm_VHALaNxrP7u%2BDp2fBsZ1PsgQ%40mail.gmail.com.

Reply via email to