mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
frontend settings db migration
This commit is contained in:
parent
c0f799a807
commit
8f2687e390
39
src/documents/migrations/1019_frontendsettings.py
Normal file
39
src/documents/migrations/1019_frontendsettings.py
Normal 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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -9,6 +9,8 @@ import pathvalidate
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
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 import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from documents.parsers import get_default_file_extension
|
from documents.parsers import get_default_file_extension
|
||||||
@ -465,3 +467,23 @@ class FileInfo:
|
|||||||
cls._mangle_property(properties, "created")
|
cls._mangle_property(properties, "created")
|
||||||
cls._mangle_property(properties, "title")
|
cls._mangle_property(properties, "title")
|
||||||
return cls(**properties)
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user