mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
from django.db import models
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from tinymce import models as tinymce
|
|
|
|
from ram.models import PrivateDocument
|
|
from metadata.models import Decoder, Shop, Tag
|
|
from roster.models import RollingStock
|
|
from bookshelf.models import Book, Catalog
|
|
|
|
|
|
class GenericDocument(PrivateDocument):
|
|
notes = tinymce.HTMLField(blank=True)
|
|
tags = models.ManyToManyField(Tag, blank=True, related_name="document")
|
|
|
|
class Meta:
|
|
verbose_name_plural = "Generic documents"
|
|
|
|
|
|
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
|
|
)
|
|
date = models.DateField()
|
|
shop = models.ForeignKey(
|
|
Shop, on_delete=models.SET_NULL, null=True, blank=True
|
|
)
|
|
file = models.FileField(
|
|
upload_to="files/invoices/",
|
|
)
|
|
notes = tinymce.HTMLField(blank=True)
|
|
|
|
|
|
class DecoderDocument(PrivateDocument):
|
|
decoder = models.ForeignKey(
|
|
Decoder, on_delete=models.CASCADE, related_name="document"
|
|
)
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["decoder", "file"], name="unique_decoder_file"
|
|
)
|
|
]
|
|
|
|
|
|
class BookDocument(PrivateDocument):
|
|
book = models.ForeignKey(
|
|
Book, on_delete=models.CASCADE, related_name="document"
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name_plural = "Book documents"
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["book", "file"], name="unique_book_file"
|
|
)
|
|
]
|
|
|
|
|
|
class CatalogDocument(PrivateDocument):
|
|
catalog = models.ForeignKey(
|
|
Catalog, on_delete=models.CASCADE, related_name="document"
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name_plural = "Catalog documents"
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["catalog", "file"], name="unique_catalog_file"
|
|
)
|
|
]
|
|
|
|
|
|
class RollingStockDocument(PrivateDocument):
|
|
rolling_stock = models.ForeignKey(
|
|
RollingStock, on_delete=models.CASCADE, related_name="document"
|
|
)
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["rolling_stock", "file"], name="unique_stock_file"
|
|
)
|
|
]
|