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
)

View File

@@ -7,11 +7,12 @@ from django.dispatch.dispatcher import receiver
from django.core.exceptions import ValidationError
from django_countries.fields import CountryField
from ram.models import SimpleBaseModel
from ram.utils import DeduplicatedStorage, get_image_preview, slugify
from ram.managers import PublicManager
class Property(models.Model):
class Property(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
private = models.BooleanField(
default=False,
@@ -28,7 +29,7 @@ class Property(models.Model):
objects = PublicManager()
class Manufacturer(models.Model):
class Manufacturer(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
slug = models.CharField(max_length=128, unique=True, editable=False)
category = models.CharField(
@@ -68,7 +69,7 @@ class Manufacturer(models.Model):
logo_thumbnail.short_description = "Preview"
class Company(models.Model):
class Company(SimpleBaseModel):
name = models.CharField(max_length=64, unique=True)
slug = models.CharField(max_length=64, unique=True, editable=False)
extended_name = models.CharField(max_length=128, blank=True)
@@ -106,7 +107,7 @@ class Company(models.Model):
logo_thumbnail.short_description = "Preview"
class Decoder(models.Model):
class Decoder(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
manufacturer = models.ForeignKey(
Manufacturer,
@@ -142,7 +143,7 @@ def calculate_ratio(ratio):
raise ValidationError("Invalid ratio format")
class Scale(models.Model):
class Scale(SimpleBaseModel):
scale = models.CharField(max_length=32, unique=True)
slug = models.CharField(max_length=32, unique=True, editable=False)
ratio = models.CharField(max_length=16, validators=[calculate_ratio])
@@ -177,7 +178,7 @@ def scale_save(sender, instance, **kwargs):
instance.ratio_int = calculate_ratio(instance.ratio)
class RollingStockType(models.Model):
class RollingStockType(SimpleBaseModel):
type = models.CharField(max_length=64)
order = models.PositiveSmallIntegerField()
category = models.CharField(
@@ -207,7 +208,7 @@ class RollingStockType(models.Model):
return "{0} {1}".format(self.type, self.category)
class Tag(models.Model):
class Tag(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
slug = models.CharField(max_length=128, unique=True)
@@ -227,7 +228,7 @@ class Tag(models.Model):
)
class Shop(models.Model):
class Shop(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
country = CountryField(blank=True)
website = models.URLField(blank=True)