mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Implement documents inline for books and catalogs
This commit is contained in:
@@ -2,7 +2,13 @@ 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, Catalog
|
BaseBookProperty,
|
||||||
|
BaseBookImage,
|
||||||
|
BaseBookDocument,
|
||||||
|
Book,
|
||||||
|
Author,
|
||||||
|
Publisher,
|
||||||
|
Catalog,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -15,6 +21,13 @@ class BookImageInline(SortableInlineAdminMixin, admin.TabularInline):
|
|||||||
verbose_name = "Image"
|
verbose_name = "Image"
|
||||||
|
|
||||||
|
|
||||||
|
class BookDocInline(admin.TabularInline):
|
||||||
|
model = BaseBookDocument
|
||||||
|
min_num = 0
|
||||||
|
extra = 0
|
||||||
|
classes = ["collapse"]
|
||||||
|
|
||||||
|
|
||||||
class BookPropertyInline(admin.TabularInline):
|
class BookPropertyInline(admin.TabularInline):
|
||||||
model = BaseBookProperty
|
model = BaseBookProperty
|
||||||
min_num = 0
|
min_num = 0
|
||||||
@@ -26,7 +39,11 @@ class BookPropertyInline(admin.TabularInline):
|
|||||||
|
|
||||||
@admin.register(Book)
|
@admin.register(Book)
|
||||||
class BookAdmin(SortableAdminBase, admin.ModelAdmin):
|
class BookAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
inlines = (BookImageInline, BookPropertyInline,)
|
inlines = (
|
||||||
|
BookPropertyInline,
|
||||||
|
BookImageInline,
|
||||||
|
BookDocInline,
|
||||||
|
)
|
||||||
list_display = (
|
list_display = (
|
||||||
"title",
|
"title",
|
||||||
"get_authors",
|
"get_authors",
|
||||||
@@ -83,7 +100,10 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(Author)
|
@admin.register(Author)
|
||||||
class AuthorAdmin(admin.ModelAdmin):
|
class AuthorAdmin(admin.ModelAdmin):
|
||||||
search_fields = ("first_name", "last_name",)
|
search_fields = (
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
)
|
||||||
list_filter = ("last_name",)
|
list_filter = ("last_name",)
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +115,11 @@ class PublisherAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(Catalog)
|
@admin.register(Catalog)
|
||||||
class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
|
class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
inlines = (BookImageInline, BookPropertyInline,)
|
inlines = (
|
||||||
|
BookPropertyInline,
|
||||||
|
BookImageInline,
|
||||||
|
BookDocInline,
|
||||||
|
)
|
||||||
list_display = (
|
list_display = (
|
||||||
"manufacturer",
|
"manufacturer",
|
||||||
"years",
|
"years",
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
# Generated by Django 5.1.2 on 2024-12-22 20:38
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
import ram.utils
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookshelf", "0016_basebook_book_catalogue"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="basebook",
|
||||||
|
options={},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="BaseBookDocument",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("description", models.CharField(blank=True, max_length=128)),
|
||||||
|
(
|
||||||
|
"file",
|
||||||
|
models.FileField(
|
||||||
|
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("private", models.BooleanField(default=False)),
|
||||||
|
(
|
||||||
|
"book",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="document",
|
||||||
|
to="bookshelf.basebook",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"unique_together": {("book", "file")},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2024-12-22 20:44
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookshelf", "0017_alter_basebook_options_basebookdocument"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="basebookdocument",
|
||||||
|
options={"verbose_name_plural": "Documents"},
|
||||||
|
),
|
||||||
|
]
|
@@ -9,7 +9,7 @@ from tinymce import models as tinymce
|
|||||||
|
|
||||||
from metadata.models import Tag
|
from metadata.models import Tag
|
||||||
from ram.utils import DeduplicatedStorage
|
from ram.utils import DeduplicatedStorage
|
||||||
from ram.models import BaseModel, Image, PropertyInstance
|
from ram.models import BaseModel, Image, Document, PropertyInstance
|
||||||
from metadata.models import Scale, Manufacturer
|
from metadata.models import Scale, Manufacturer
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +83,16 @@ class BaseBookImage(Image):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseBookDocument(Document):
|
||||||
|
book = models.ForeignKey(
|
||||||
|
BaseBook, on_delete=models.CASCADE, related_name="document"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "Documents"
|
||||||
|
unique_together = ("book", "file")
|
||||||
|
|
||||||
|
|
||||||
class BaseBookProperty(PropertyInstance):
|
class BaseBookProperty(PropertyInstance):
|
||||||
book = models.ForeignKey(
|
book = models.ForeignKey(
|
||||||
BaseBook,
|
BaseBook,
|
||||||
|
@@ -32,6 +32,7 @@ class Document(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
verbose_name_plural = "Documents"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0}".format(os.path.basename(self.file.name))
|
return "{0}".format(os.path.basename(self.file.name))
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.1.2 on 2024-12-22 20:38
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("roster", "0028_rollingstock_published"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="rollingstockimage",
|
||||||
|
options={"ordering": ["order"], "verbose_name_plural": "Images"},
|
||||||
|
),
|
||||||
|
]
|
Reference in New Issue
Block a user