Add documents to decoders (#22)

* Add decoder documents support
* Use abstract model for Documents
* Increase version
* Code cleanup
This commit is contained in:
2023-10-01 00:03:41 +02:00
committed by GitHub
parent 9483648a1f
commit 5d536ce568
16 changed files with 161 additions and 60 deletions

View File

@@ -1,11 +1,10 @@
from urllib.parse import quote
from django.db import models
from django.urls import reverse
from django.conf import settings
from django.dispatch.dispatcher import receiver
from django_countries.fields import CountryField
from ram.models import Document
from ram.utils import DeduplicatedStorage, get_image_preview, slugify
@@ -88,7 +87,7 @@ class Decoder(models.Model):
manufacturer = models.ForeignKey(
Manufacturer,
on_delete=models.CASCADE,
limit_choices_to={"category": "model"},
limit_choices_to={"category": "accessory"},
)
version = models.CharField(max_length=64, blank=True)
sound = models.BooleanField(default=False)
@@ -105,6 +104,15 @@ class Decoder(models.Model):
image_thumbnail.short_description = "Preview"
class DecoderDocument(Document):
decoder = models.ForeignKey(
Decoder, on_delete=models.CASCADE, related_name="document"
)
class Meta:
unique_together = ("decoder", "file")
class Scale(models.Model):
scale = models.CharField(max_length=32, unique=True)
slug = models.CharField(max_length=32, unique=True, editable=False)
@@ -167,7 +175,6 @@ class Tag(models.Model):
)
@receiver(models.signals.pre_save, sender=Manufacturer)
@receiver(models.signals.pre_save, sender=Company)
@receiver(models.signals.pre_save, sender=Scale)