mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Complete the implementation of document repository and add invoices
This commit is contained in:
@@ -3,7 +3,8 @@ from django.contrib import admin
|
||||
from ram.admin import publish, unpublish
|
||||
from repository.models import (
|
||||
GenericDocument,
|
||||
BaseBookDocument,
|
||||
InvoiceDocument,
|
||||
# BaseBookDocument,
|
||||
DecoderDocument,
|
||||
RollingStockDocument
|
||||
)
|
||||
@@ -54,6 +55,51 @@ class GenericDocumentAdmin(admin.ModelAdmin):
|
||||
actions = [publish, unpublish]
|
||||
|
||||
|
||||
@admin.register(InvoiceDocument)
|
||||
class InvoiceDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size", "creation_time", "updated_time")
|
||||
list_display = (
|
||||
"__str__",
|
||||
"description",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
autocomplete_fields = ("rolling_stock", "book", "catalog")
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"description",
|
||||
"rolling_stock",
|
||||
"book",
|
||||
"catalog",
|
||||
"file",
|
||||
"size",
|
||||
)
|
||||
},
|
||||
),
|
||||
(
|
||||
"Notes",
|
||||
{"classes": ("collapse",), "fields": ("notes",)},
|
||||
),
|
||||
(
|
||||
"Audit",
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# @admin.register(BaseBookDocument)
|
||||
# class BookDocumentAdmin(admin.ModelAdmin):
|
||||
# readonly_fields = ("size",)
|
||||
|
@@ -66,8 +66,6 @@ def migrate_book(apps, schema_editor):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0022_basebook_shop"),
|
||||
("metadata", "0023_shop"),
|
||||
|
@@ -0,0 +1,66 @@
|
||||
# Generated by Django 5.1.4 on 2025-02-09 15:16
|
||||
|
||||
import ram.utils
|
||||
import tinymce.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0023_delete_basebookdocument"),
|
||||
("repository", "0002_alter_decoderdocument_options_and_more"),
|
||||
("roster", "0036_delete_rollingstockdocument"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="basebookdocument",
|
||||
options={"verbose_name_plural": "Bookshelf Documents"},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="genericdocument",
|
||||
options={"verbose_name_plural": "Generic documents"},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="InvoiceDocument",
|
||||
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/"
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
("private", models.BooleanField(default=True, editable=False)),
|
||||
("notes", tinymce.models.HTMLField(blank=True)),
|
||||
(
|
||||
"book",
|
||||
models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="bookshelf.basebook"
|
||||
),
|
||||
),
|
||||
(
|
||||
"rolling_stock",
|
||||
models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="roster.rollingstock"
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Invoice",
|
||||
"verbose_name_plural": "Invoices",
|
||||
},
|
||||
),
|
||||
]
|
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 5.1.4 on 2025-02-09 17:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0023_delete_basebookdocument"),
|
||||
("repository", "0003_alter_basebookdocument_options_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="invoicedocument",
|
||||
name="catalog",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="bookshelf.catalog"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="invoicedocument",
|
||||
name="book",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="bookshelf.book"
|
||||
),
|
||||
),
|
||||
]
|
@@ -1,30 +1,43 @@
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import fields
|
||||
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram.models import Document
|
||||
from ram.models import PrivateDocument
|
||||
from metadata.models import Decoder, Tag
|
||||
from roster.models import RollingStock
|
||||
from bookshelf.models import BaseBook
|
||||
from bookshelf.models import Book, Catalog, BaseBook
|
||||
|
||||
|
||||
class GenericDocument(Document):
|
||||
class GenericDocument(PrivateDocument):
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
tags = models.ManyToManyField(Tag, blank=True, related_name="document")
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Generic Documents"
|
||||
verbose_name_plural = "Generic documents"
|
||||
|
||||
|
||||
class InvoiceDocument(Document):
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = fields.GenericForeignKey("content_type", "object_id")
|
||||
class InvoiceDocument(PrivateDocument):
|
||||
private = models.BooleanField(default=True, editable=False)
|
||||
rolling_stock = models.ManyToManyField(
|
||||
RollingStock, related_name="invoice",
|
||||
blank=True
|
||||
)
|
||||
book = models.ManyToManyField(
|
||||
Book, related_name="invoice",
|
||||
blank=True
|
||||
)
|
||||
catalog = models.ManyToManyField(
|
||||
Catalog, related_name="invoice",
|
||||
blank=True
|
||||
)
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Invoice"
|
||||
verbose_name_plural = "Invoices"
|
||||
|
||||
|
||||
class DecoderDocument(Document):
|
||||
class DecoderDocument(PrivateDocument):
|
||||
decoder = models.ForeignKey(
|
||||
Decoder, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
@@ -38,13 +51,13 @@ class DecoderDocument(Document):
|
||||
]
|
||||
|
||||
|
||||
class BaseBookDocument(Document):
|
||||
class BaseBookDocument(PrivateDocument):
|
||||
book = models.ForeignKey(
|
||||
BaseBook, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Documents"
|
||||
verbose_name_plural = "Bookshelf Documents"
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["book", "file"],
|
||||
@@ -53,7 +66,7 @@ class BaseBookDocument(Document):
|
||||
]
|
||||
|
||||
|
||||
class RollingStockDocument(Document):
|
||||
class RollingStockDocument(PrivateDocument):
|
||||
rolling_stock = models.ForeignKey(
|
||||
RollingStock, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
|
Reference in New Issue
Block a user