Add more components + base for history

This commit is contained in:
2024-10-01 15:42:18 +02:00
parent fb4d566007
commit 8f9c83dc2a
38 changed files with 1374 additions and 665 deletions
@@ -0,0 +1,57 @@
# Generated by Django 5.1.1 on 2024-10-01 13:41
import django.db.models.deletion
import simple_history.models
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("users", "0005_alter_usersettings_custom_identifier_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="HistoricalUserSettings",
fields=[
("id", models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
("name", models.TextField(blank=True, max_length=2048, null=True)),
("description", models.TextField(blank=True, max_length=2048, null=True)),
("custom_identifier", models.TextField(blank=True, max_length=2048, null=True)),
("created_at", models.DateTimeField(blank=True, editable=False)),
("last_modified_at", models.DateTimeField(blank=True, editable=False)),
("public_key", models.TextField(max_length=2048, null=True)),
("private_key", models.TextField(max_length=2048, null=True)),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
("history_type", models.CharField(choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")], max_length=1)),
(
"history_user",
models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="+", to=settings.AUTH_USER_MODEL),
),
(
"user",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "historical user settings",
"verbose_name_plural": "historical user settingss",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
+5
View File
@@ -5,6 +5,9 @@ from django.db import models
from app.utils.models import BaseModel
from simple_history.models import HistoricalRecords
User = get_user_model()
@@ -14,3 +17,5 @@ class UserSettings(BaseModel):
# The private and public key are wrapped with the AES key from the front-end
public_key = models.TextField(max_length=2048, null=True)
private_key = models.TextField(max_length=2048, null=True)
history = HistoricalRecords()