Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow customized BooleanFieldListFilter to display with horizontal styling #981

Open
justinqian42 opened this issue Jan 16, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@justinqian42
Copy link

justinqian42 commented Jan 16, 2025

Do you have any examples?

For example:

Image

Is it a third party application feature request?

For example: No

In case of third party application, when it was updated last time?

For example: N/A

Describe your feature request

In the current filter template, line 14 checks if a filter is with the default BooleanFieldListFilter class, and if yes, apply the special horizontal styling.

However, it applies to the default BooleanFieldListFilter only. So when people like me want to customize it to display other options rather than "True" or "False" with a different class name such as "StatusBooleanFieldListFilter", it will display in the default vertical styling.

Suggesting to change it to
{% if "BooleanFieldListFilter" in spec|class_name %}
so that as long as people name the inherited filter class with string BooleanFieldListFilter in, the styling would work.

Please see the attached screenshot.

Attaching my code snippet (use case) for reference.

class StatusBooleanFieldListFilter(BooleanFieldListFilter):
    def __init__(self, field, request, params, model, model_admin, field_path):
        self.title = "Status"
        super().__init__(field, request, params, model, model_admin, field_path)

    def choices(self, changelist):
        for lookup, title in ((None, "All"), ("1", "Up"), ("0", "Down")):
            yield {
                "selected": self.lookup_val == lookup,
                "query_string": changelist.get_query_string(
                    {self.lookup_kwarg: lookup}
                ),
                "display": title,
            }

Please let me know if a PR is preferred. Happy to raise one.

Thanks in advance!

@lukasvinclav lukasvinclav added the enhancement New feature or request label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants