From 119a013c7fae47cb592ecc1be4b867f727ca91c0 Mon Sep 17 00:00:00 2001 From: Bao Doan Date: Thu, 12 Nov 2020 23:46:08 +0900 Subject: [PATCH] final flexible admin filter --- project/app/admin.py | 10 +- project/app/models.py | 9 +- project/templates/admin/change_list.html | 332 +++++++++++++++++++++++ 3 files changed, 344 insertions(+), 7 deletions(-) diff --git a/project/app/admin.py b/project/app/admin.py index d1f766b..91c5749 100644 --- a/project/app/admin.py +++ b/project/app/admin.py @@ -344,9 +344,9 @@ class HoDanAdmin(NumericFilterModelAdmin, MapAdmin, HoDanHistoryAdmin, admin.Mod list_editable = () list_filter = ( ('status', RelatedDropdownFilter), - TinhAdminFilter, - HuyenAdminFilter, - XaAdminFilter, + ('tinh', RelatedDropdownFilter), + ('huyen', RelatedDropdownFilter), + ('xa', RelatedDropdownFilter), ) search_fields = ('name', 'phone', 'note', 'id') actions = [export_ho_dan_as_excel_action()] @@ -449,7 +449,9 @@ class Media: css = { 'all': (f'/static/css/custom.css?v={REVISION}',) } - + js = ( + '//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js' # jquery + ) class HoDanCuuHoStatisticBase(admin.ModelAdmin): class Meta: diff --git a/project/app/models.py b/project/app/models.py index fe786fc..413efbf 100644 --- a/project/app/models.py +++ b/project/app/models.py @@ -219,7 +219,8 @@ class HoDan(models.Model): people_number = models.PositiveIntegerField(blank=True, null=True, default=1, verbose_name="Số người") tinh = models.ForeignKey( Tinh, blank=True, null=True, on_delete=models.CASCADE, - related_name="hodan_reversed" + related_name="hodan_reversed", + verbose_name="Tỉnh" ) huyen = ChainedForeignKey( Huyen, @@ -231,7 +232,8 @@ class HoDan(models.Model): blank=True, null=True, related_name="hodan_reversed", - on_delete=models.CASCADE) + on_delete=models.CASCADE, + verbose_name="Huyện") xa = ChainedForeignKey( Xa, @@ -243,7 +245,8 @@ class HoDan(models.Model): blank=True, null=True, related_name="hodan_reversed", - on_delete=models.CASCADE) + on_delete=models.CASCADE, + verbose_name="Xã") thon = models.ForeignKey( Thon, diff --git a/project/templates/admin/change_list.html b/project/templates/admin/change_list.html index 7183d47..995ef15 100644 --- a/project/templates/admin/change_list.html +++ b/project/templates/admin/change_list.html @@ -1,5 +1,337 @@ {% extends "admin/change_list.html" %} {% load i18n admin_urls static admin_list %} +{% block extrahead %} + + + + + + + + +{% endblock %} {% block extrastyle %} {{ block.super }}