Complete Catalogs with code refactoring

This commit is contained in:
2024-12-22 18:53:47 +01:00
parent 64f616d89f
commit cbf6c942b9
10 changed files with 118 additions and 59 deletions

View File

@@ -35,6 +35,7 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
"number_of_pages",
"published",
)
autocomplete_fields = ("authors", "publisher")
readonly_fields = ("creation_time", "updated_time")
search_fields = ("title", "publisher__name", "authors__last_name")
list_filter = ("publisher__name", "authors")
@@ -101,6 +102,7 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
"get_scales",
"published",
)
autocomplete_fields = ("manufacturer",)
readonly_fields = ("creation_time", "updated_time")
search_fields = ("manufacturer__name", "years", "scales__scale")
list_filter = ("manufacturer__name", "publication_year", "scales__scale")

View File

@@ -127,8 +127,6 @@ class Migration(migrations.Migration):
(
"manufacturer",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="metadata.manufacturer",
),

View File

@@ -108,15 +108,16 @@ class Book(BaseBook):
return self.publisher.name
def get_absolute_url(self):
return reverse("book", kwargs={"uuid": self.uuid})
return reverse(
"bookshelf_item",
kwargs={"selector": "book", "uuid": self.uuid}
)
class Catalog(BaseBook):
manufacturer = models.ForeignKey(
Manufacturer,
on_delete=models.CASCADE,
null=True,
blank=True,
)
years = models.CharField(max_length=12)
scales = models.ManyToManyField(Scale)
@@ -125,8 +126,15 @@ class Catalog(BaseBook):
ordering = ["manufacturer", "publication_year"]
def __str__(self):
scales = "/".join([s.scale for s in self.scales.all()])
scales = self.get_scales
return "%s %s %s" % (self.manufacturer.name, self.years, scales)
def get_absolute_url(self):
return reverse("catalog", kwargs={"uuid": self.uuid})
return reverse(
"bookshelf_item",
kwargs={"selector": "catalog", "uuid": self.uuid}
)
@property
def get_scales(self):
return "/".join([s.scale for s in self.scales.all()])