mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-04 10:00:40 +01:00
More aggressing code reuse
This commit is contained in:
@@ -161,15 +161,7 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||
def get_queryset(self, request):
|
||||
"""Optimize queryset with select_related and prefetch_related."""
|
||||
qs = super().get_queryset(request)
|
||||
return qs.select_related(
|
||||
'rolling_class',
|
||||
'rolling_class__company',
|
||||
'rolling_class__type',
|
||||
'manufacturer',
|
||||
'scale',
|
||||
'decoder',
|
||||
'shop',
|
||||
).prefetch_related('tags', 'image')
|
||||
return qs.with_related()
|
||||
|
||||
@admin.display(description="Country")
|
||||
def country_flag(self, obj):
|
||||
|
||||
@@ -11,7 +11,7 @@ from tinymce import models as tinymce
|
||||
|
||||
from ram.models import BaseModel, Image, PropertyInstance
|
||||
from ram.utils import DeduplicatedStorage, slugify
|
||||
from ram.managers import PublicManager, RollingStockManager
|
||||
from ram.managers import RollingStockManager
|
||||
from metadata.models import (
|
||||
Scale,
|
||||
Manufacturer,
|
||||
@@ -120,6 +120,8 @@ class RollingStock(BaseModel):
|
||||
Tag, related_name="rolling_stock", blank=True
|
||||
)
|
||||
|
||||
objects = RollingStockManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ["rolling_class", "road_number_int"]
|
||||
verbose_name_plural = "Rolling stock"
|
||||
|
||||
Reference in New Issue
Block a user