Code refactoring to simplify template data contexts (#55)

* Fix a search filter when no catalogs are returned
* Code refactoring to simplify templates
* Remove duplicated code
* Remove dead code
* More improvements, clean up and add featured items in homepage
* Fix a type and better page navigation
This commit is contained in:
2025-12-24 15:38:07 +01:00
committed by GitHub
parent 98d2e7beab
commit 676418cb67
32 changed files with 466 additions and 433 deletions

View File

@@ -47,12 +47,12 @@ class ScaleAdmin(admin.ModelAdmin):
@admin.register(Company)
class CompanyAdmin(admin.ModelAdmin):
readonly_fields = ("logo_thumbnail",)
list_display = ("name", "country_flag")
list_display = ("name", "country_flag_name")
list_filter = ("name", "country")
search_fields = ("name",)
@admin.display(description="Country")
def country_flag(self, obj):
def country_flag_name(self, obj):
return format_html(
'<img src="{}" /> {}', obj.country.flag, obj.country.name
)
@@ -61,12 +61,12 @@ class CompanyAdmin(admin.ModelAdmin):
@admin.register(Manufacturer)
class ManufacturerAdmin(admin.ModelAdmin):
readonly_fields = ("logo_thumbnail",)
list_display = ("name", "category", "country_flag")
list_display = ("name", "category", "country_flag_name")
list_filter = ("category",)
search_fields = ("name",)
@admin.display(description="Country")
def country_flag(self, obj):
def country_flag_name(self, obj):
return format_html(
'<img src="{}" /> {}', obj.country.flag, obj.country.name
)
@@ -88,6 +88,12 @@ class RollingStockTypeAdmin(SortableAdminMixin, admin.ModelAdmin):
@admin.register(Shop)
class ShopAdmin(admin.ModelAdmin):
list_display = ("name", "on_line", "active")
list_display = ("name", "on_line", "active", "country_flag_name")
list_filter = ("on_line", "active")
search_fields = ("name",)
@admin.display(description="Country")
def country_flag_name(self, obj):
return format_html(
'<img src="{}" /> {}', obj.country.flag, obj.country.name
)