mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add support for generic documents (admin only) (#44)
* Add support for generic documents * Add publish / unpublish actions * Minor improvements to models properties
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from adminsortable2.admin import SortableAdminMixin
|
||||
|
||||
from ram.admin import publish, unpublish
|
||||
from metadata.models import (
|
||||
Property,
|
||||
Decoder,
|
||||
@@ -10,6 +11,7 @@ from metadata.models import (
|
||||
Company,
|
||||
Tag,
|
||||
RollingStockType,
|
||||
GenericDocument,
|
||||
)
|
||||
|
||||
|
||||
@@ -70,3 +72,20 @@ class RollingStockTypeAdmin(SortableAdminMixin, admin.ModelAdmin):
|
||||
list_display = ("__str__",)
|
||||
list_filter = ("type", "category")
|
||||
search_fields = ("type", "category")
|
||||
|
||||
|
||||
@admin.register(GenericDocument)
|
||||
class GenericDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size",)
|
||||
list_display = (
|
||||
"__str__",
|
||||
"description",
|
||||
"private",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
actions = [publish, unpublish]
|
||||
|
40
ram/metadata/migrations/0021_genericdocument.py
Normal file
40
ram/metadata/migrations/0021_genericdocument.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Generated by Django 5.1.4 on 2025-01-17 09:31
|
||||
|
||||
import ram.utils
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("metadata", "0020_alter_decoderdocument_unique_together_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="GenericDocument",
|
||||
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)),
|
||||
("tags", models.ManyToManyField(blank=True, to="metadata.tag")),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Generic Documents",
|
||||
},
|
||||
),
|
||||
]
|
@@ -236,6 +236,13 @@ class Tag(models.Model):
|
||||
)
|
||||
|
||||
|
||||
class GenericDocument(Document):
|
||||
tags = models.ManyToManyField(Tag, blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Generic Documents"
|
||||
|
||||
|
||||
@receiver(models.signals.pre_save, sender=Manufacturer)
|
||||
@receiver(models.signals.pre_save, sender=Company)
|
||||
@receiver(models.signals.pre_save, sender=Scale)
|
||||
|
Reference in New Issue
Block a user