From b686e3762bffbe040d677e392c2be531314dafd5 Mon Sep 17 00:00:00 2001 From: Martin Tan Date: Mon, 24 Jul 2023 01:43:48 +0800 Subject: [PATCH] Add default_metadata in DocumentType --- ...alter_documenttype_add_default_metadata.py | 24 +++++++++++++++++++ src/documents/models.py | 8 +++++++ 2 files changed, 32 insertions(+) create mode 100644 src/documents/migrations/1037_alter_documenttype_add_default_metadata.py diff --git a/src/documents/migrations/1037_alter_documenttype_add_default_metadata.py b/src/documents/migrations/1037_alter_documenttype_add_default_metadata.py new file mode 100644 index 000000000..5cc298913 --- /dev/null +++ b/src/documents/migrations/1037_alter_documenttype_add_default_metadata.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.7 on 2023-07-23 17:36 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '1036_add_metadata'), + ] + + operations = [ + migrations.AddField( + model_name='documenttype', + name='default_metadata', + field=models.JSONField(blank=True, help_text='Default JSON metadata', null=True, verbose_name='default_metadata'), + ), + migrations.AlterField( + model_name='metadata', + name='document', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='document', to='documents.document', verbose_name='document'), + ), + ] \ No newline at end of file diff --git a/src/documents/models.py b/src/documents/models.py index 998884fad..df7ca2b41 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -112,6 +112,14 @@ class Tag(MatchingModel): class DocumentType(MatchingModel): + default_metadata = models.JSONField( + _("default_metadata"), + # Source: https://stackoverflow.com/a/47590145/5575610 + null=True, + blank=True, + help_text=_("Default JSON metadata"), + ) + class Meta(MatchingModel.Meta): verbose_name = _("document type") verbose_name_plural = _("document types")