django-more-admin-filters
django-more-admin-filters copied to clipboard
Edit template
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?
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"
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?
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.
Hmm that seems a bit complex, its fine like this I suppose.
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.
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?
Alright, reading your docs:
Instead of subclass django_filters.FilterSet, use the AdminFilterSetSay I'm using
MultiSelectRelatedDropdownFilter(MultiSelectRelatedFilter)from this repo, which usesadmin.RelatedFieldListFilterin itsMultiSelectRelatedFilterclass. Do I go replaceadmin.RelatedFieldListFilterwithAdminFilterSet?
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.