frontend settings db migration

This commit is contained in:
Michael Shamoon 2022-05-06 22:10:35 -07:00
parent c0f799a807
commit 8f2687e390
2 changed files with 61 additions and 0 deletions

View File

@ -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,
),
),
],
),
]

View File

@ -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)