diff --git a/src/documents/migrations/1019_frontendsettings.py b/src/documents/migrations/1019_frontendsettings.py new file mode 100644 index 000000000..1da17c974 --- /dev/null +++ b/src/documents/migrations/1019_frontendsettings.py @@ -0,0 +1,39 @@ +# Generated by Django 4.0.4 on 2022-05-07 05:10 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("documents", "1018_alter_savedviewfilterrule_value"), + ] + + operations = [ + migrations.CreateModel( + name="FrontendSettings", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("settings", models.JSONField(null=True)), + ( + "user", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name="frontend_settings", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ] diff --git a/src/documents/models.py b/src/documents/models.py index 206df4e8a..198bf27b2 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -9,6 +9,8 @@ import pathvalidate from django.conf import settings from django.contrib.auth.models import User from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver from django.utils import timezone from django.utils.translation import gettext_lazy as _ from documents.parsers import get_default_file_extension @@ -465,3 +467,23 @@ class FileInfo: cls._mangle_property(properties, "created") cls._mangle_property(properties, "title") return cls(**properties) + + +# Extending User Model Using a One-To-One Link +class FrontendSettings(models.Model): + + user = models.OneToOneField( + User, + on_delete=models.CASCADE, + related_name="frontend_settings", + ) + settings = models.JSONField(null=True) + + def __str__(self): + return self.user.username + + +@receiver(post_save, sender=User) +def create_user_frontend_settings(sender, instance, created, **kwargs): + if created: + FrontendSettings.objects.create(user=instance)