mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
Enable Catalogs in Admin
This commit is contained in:
@@ -2,7 +2,7 @@ from django.contrib import admin
|
|||||||
from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin
|
from adminsortable2.admin import SortableAdminBase, SortableInlineAdminMixin
|
||||||
|
|
||||||
from bookshelf.models import (
|
from bookshelf.models import (
|
||||||
BaseBookProperty, BaseBookImage, Book, Author, Publisher
|
BaseBookProperty, BaseBookImage, Book, Author, Publisher, Catalog
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -12,6 +12,7 @@ class BookImageInline(SortableInlineAdminMixin, admin.TabularInline):
|
|||||||
extra = 0
|
extra = 0
|
||||||
readonly_fields = ("image_thumbnail",)
|
readonly_fields = ("image_thumbnail",)
|
||||||
classes = ["collapse"]
|
classes = ["collapse"]
|
||||||
|
verbose_name = "Image"
|
||||||
|
|
||||||
|
|
||||||
class BookPropertyInline(admin.TabularInline):
|
class BookPropertyInline(admin.TabularInline):
|
||||||
@@ -19,6 +20,8 @@ class BookPropertyInline(admin.TabularInline):
|
|||||||
min_num = 0
|
min_num = 0
|
||||||
extra = 0
|
extra = 0
|
||||||
autocomplete_fields = ("property",)
|
autocomplete_fields = ("property",)
|
||||||
|
verbose_name = "Property"
|
||||||
|
verbose_name_plural = "Properties"
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Book)
|
@admin.register(Book)
|
||||||
@@ -26,11 +29,11 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
|
|||||||
inlines = (BookImageInline, BookPropertyInline,)
|
inlines = (BookImageInline, BookPropertyInline,)
|
||||||
list_display = (
|
list_display = (
|
||||||
"title",
|
"title",
|
||||||
"published",
|
|
||||||
"get_authors",
|
"get_authors",
|
||||||
"get_publisher",
|
"get_publisher",
|
||||||
"publication_year",
|
"publication_year",
|
||||||
"number_of_pages"
|
"number_of_pages",
|
||||||
|
"published",
|
||||||
)
|
)
|
||||||
readonly_fields = ("creation_time", "updated_time")
|
readonly_fields = ("creation_time", "updated_time")
|
||||||
search_fields = ("title", "publisher__name", "authors__last_name")
|
search_fields = ("title", "publisher__name", "authors__last_name")
|
||||||
@@ -87,3 +90,53 @@ class AuthorAdmin(admin.ModelAdmin):
|
|||||||
class PublisherAdmin(admin.ModelAdmin):
|
class PublisherAdmin(admin.ModelAdmin):
|
||||||
list_display = ("name", "country")
|
list_display = ("name", "country")
|
||||||
search_fields = ("name",)
|
search_fields = ("name",)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Catalog)
|
||||||
|
class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
|
inlines = (BookImageInline, BookPropertyInline,)
|
||||||
|
list_display = (
|
||||||
|
"manufacturer",
|
||||||
|
"years",
|
||||||
|
"get_scales",
|
||||||
|
"published",
|
||||||
|
)
|
||||||
|
readonly_fields = ("creation_time", "updated_time")
|
||||||
|
search_fields = ("manufacturer__name", "years", "scales__scale")
|
||||||
|
list_filter = ("manufacturer__name", "publication_year", "scales__scale")
|
||||||
|
|
||||||
|
fieldsets = (
|
||||||
|
(
|
||||||
|
None,
|
||||||
|
{
|
||||||
|
"fields": (
|
||||||
|
"published",
|
||||||
|
"manufacturer",
|
||||||
|
"years",
|
||||||
|
"scales",
|
||||||
|
"ISBN",
|
||||||
|
"language",
|
||||||
|
"number_of_pages",
|
||||||
|
"publication_year",
|
||||||
|
"description",
|
||||||
|
"purchase_date",
|
||||||
|
"notes",
|
||||||
|
"tags",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Audit",
|
||||||
|
{
|
||||||
|
"classes": ("collapse",),
|
||||||
|
"fields": (
|
||||||
|
"creation_time",
|
||||||
|
"updated_time",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
@admin.display(description="Scales")
|
||||||
|
def get_scales(self, obj):
|
||||||
|
return ", ".join(s.scale for s in obj.scales.all())
|
||||||
|
Reference in New Issue
Block a user