django-more-admin-filters icon indicating copy to clipboard operation
django-more-admin-filters copied to clipboard

Edit template

Open Samoht1 opened this issue 4 years ago • 7 comments

Hello, first of all thanks so much for the app, wouldn't know how to do it manually. I want to personalize the filter button, give it a icon or something and make the select box a bit smaller. I imagine this is done in the template. I'm not that experience with django, is there a way to extend the template or something in my own template, how do I make that work?

EDIT: also, I have 2 filters, both using MultiSelectRelatedDropdownFilter, they both have separate filter buttons. Is there a way to implement a button that activates both filter simultaneously?

Samoht1 avatar Aug 05 '21 09:08 Samoht1

Hello !

Concerning the personalization, everything in the django admin interface is customizable, extendable or can be overwritten.

You should look a bit in the related documentation from django.

You will probably have to extend the template which contains what you want to replace, the same goes for the sytlesheets if you want to apply your own styling.

As for the second question, I am not sure to understand the expected behavior when you say "activates both filters simultaneously"

clemsau avatar Aug 11 '21 14:08 clemsau

yes I figured out how to extend the templates. For my second question I mean you have for each filter you put in there their own seperate button to apply it. Is it possible to create one button to apply all filters present?

Samoht1 avatar Aug 13 '21 07:08 Samoht1

To do that, you would need to do modifications in the Filter classes.

If you use for example the MultiSelectFilter of the library, try to understand how the choices are working:

class MultiSelectFilter(MultiSelectMixin, admin.AllValuesFieldListFilter):

    [...]

    def choices(self, changelist):
        yield {
            'selected': not self.lookup_vals and self.lookup_val_isnull is None,
            'query_string': changelist.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg_isnull]),
            'display': _('All'),
        }
        include_none = False
        for val in self.lookup_choices:
            if val is None:
                include_none = True
                continue
            val = str(val)
            qval = self.prepare_querystring_value(val)
            yield {
                'selected': qval in self.lookup_vals,
                'query_string': self.querystring_for_choices(qval, changelist),
                'display': val,
            }
        if include_none:
            yield {
                'selected': bool(self.lookup_val_isnull),
                'query_string': self.querystring_for_isnull(changelist),
                'display': self.empty_value_display,
            }

You could yield a new choice that would activate multiple filters at once if you want.

clemsau avatar Aug 13 '21 10:08 clemsau

Hmm that seems a bit complex, its fine like this I suppose.

Samoht1 avatar Aug 16 '21 05:08 Samoht1

EDIT: also, I have 2 filters, both using MultiSelectRelatedDropdownFilter, they both have separate filter buttons. Is there a way to implement a button that activates both filter simultaneously?

Hi @Samoht1 . Sorry for not answering earlier. To realize a more complex filter logic (like combining multiple fields) it might be worth to have a look at django-admin-filter.

thomst avatar Aug 16 '21 06:08 thomst

EDIT: also, I have 2 filters, both using MultiSelectRelatedDropdownFilter, they both have separate filter buttons. Is there a way to implement a button that activates both filter simultaneously?

Hi @Samoht1 . Sorry for not answering earlier. To realize a more complex filter logic (like combining multiple fields) it might be worth to have a look at django-admin-filter.

Alright, reading your docs: Instead of subclass django_filters.FilterSet, use the AdminFilterSet

Say I'm using MultiSelectRelatedDropdownFilter(MultiSelectRelatedFilter) from this repo, which uses admin.RelatedFieldListFilter in its MultiSelectRelatedFilter class. Do I go replace admin.RelatedFieldListFilter with AdminFilterSet?

Samoht1 avatar Aug 16 '21 06:08 Samoht1

Alright, reading your docs: Instead of subclass django_filters.FilterSet, use the AdminFilterSet

Say I'm using MultiSelectRelatedDropdownFilter(MultiSelectRelatedFilter) from this repo, which uses admin.RelatedFieldListFilter in its MultiSelectRelatedFilter class. Do I go replace admin.RelatedFieldListFilter with AdminFilterSet?

Django-admin-filter is built on django-filter. The above line is just an adaption of the implementation logic of django-filter. Please read their documentation too.

One thing django-admin-filter does is to provide an interface for django-filters within the filter section of the admin-page.

thomst avatar Aug 16 '21 12:08 thomst