Features: 1) Remove custom BaseAutocompleteFilter and related admin filters to streamline list filtering; 2) Simplify ProductAdmin by eliminating unused autocomplete mixin and filters;
Fixes: 1) Remove unused imports from `core/admin.py`; Extra: 1) Delete redundant `autocomplete_filter.html` template and associated filter classes for cleanup; 2) Minor refactoring of `ProductAdmin` class in alignment with the removal of filters.
This commit is contained in:
parent
67a08b69b4
commit
d008d9dd0f
3 changed files with 1 additions and 66 deletions
|
|
@ -13,7 +13,6 @@ from mptt.admin import DraggableMPTTAdmin
|
|||
|
||||
from evibes.settings import CONSTANCE_CONFIG
|
||||
|
||||
from .filters import BrandAdminFilter, CategoryAdminFilter, TagsAdminFilter, VendorAdminFilter
|
||||
from .forms import OrderForm, OrderProductForm, VendorForm
|
||||
from .models import (
|
||||
Address,
|
||||
|
|
@ -37,11 +36,6 @@ from .models import (
|
|||
)
|
||||
|
||||
|
||||
class AutocompleteFilterMixin:
|
||||
class Media:
|
||||
js = ("admin/js/autocomplete.js",)
|
||||
|
||||
|
||||
class FieldsetsMixin:
|
||||
general_fields: list = []
|
||||
relation_fields: list = []
|
||||
|
|
@ -236,7 +230,7 @@ class BrandAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin):
|
|||
|
||||
|
||||
@register(Product)
|
||||
class ProductAdmin(FieldsetsMixin, ActivationActionsMixin, AutocompleteFilterMixin, ModelAdmin):
|
||||
class ProductAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin):
|
||||
model = Product # type: ignore
|
||||
list_display = (
|
||||
"name",
|
||||
|
|
@ -251,10 +245,6 @@ class ProductAdmin(FieldsetsMixin, ActivationActionsMixin, AutocompleteFilterMix
|
|||
list_filter = (
|
||||
"is_active",
|
||||
"is_digital",
|
||||
BrandAdminFilter,
|
||||
CategoryAdminFilter,
|
||||
TagsAdminFilter,
|
||||
VendorAdminFilter,
|
||||
"created",
|
||||
"modified",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -506,47 +506,3 @@ class AddressFilter(FilterSet):
|
|||
class Meta:
|
||||
model = Address
|
||||
fields = ["uuid", "user_uuid", "user_email", "order_by"]
|
||||
|
||||
|
||||
class BaseAutocompleteFilter(SimpleListFilter):
|
||||
template = "admin/autocomplete_filter.html"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return ()
|
||||
|
||||
def choices(self, changelist):
|
||||
url = reverse(
|
||||
f"admin:{changelist.opts.app_label}_{self.parameter_name}_autocomplete"
|
||||
)
|
||||
current = changelist.params.get(self.parameter_name, "")
|
||||
html = (
|
||||
f'<input type="hidden" '
|
||||
f'class="django-autocomplete admin-autocomplete-filter" '
|
||||
f'data-autocomplete-url="{url}" '
|
||||
f'name="{self.parameter_name}" '
|
||||
f'value="{current}"/>'
|
||||
)
|
||||
# noinspection DjangoSafeString
|
||||
yield {
|
||||
"display": mark_safe(html),
|
||||
}
|
||||
|
||||
|
||||
class BrandAdminFilter(BaseAutocompleteFilter):
|
||||
title = _("By Brand")
|
||||
parameter_name = "brand"
|
||||
|
||||
|
||||
class CategoryAdminFilter(BaseAutocompleteFilter):
|
||||
title = _("By Category")
|
||||
parameter_name = "category"
|
||||
|
||||
|
||||
class TagsAdminFilter(BaseAutocompleteFilter):
|
||||
title = _("By Product tags")
|
||||
parameter_name = "tags"
|
||||
|
||||
|
||||
class VendorAdminFilter(BaseAutocompleteFilter):
|
||||
title = _("By Associated vendor")
|
||||
parameter_name = "stocks__vendor"
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
{% comment %}
|
||||
A custom filter template that
|
||||
only cares about our `display` key.
|
||||
{% endcomment %}
|
||||
|
||||
<div class="module filter-{{ spec.parameter_name|slugify }}">
|
||||
<h3>{{ spec.title }}</h3>
|
||||
{% for choice in spec.choices cl %}
|
||||
{{ choice.display|safe }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
Loading…
Reference in a new issue