Add history + more components

This commit is contained in:
2024-10-03 22:29:32 +02:00
parent 8f9c83dc2a
commit d7f0d2a7f2
18 changed files with 352 additions and 30 deletions
+1 -3
View File
@@ -157,10 +157,8 @@ USE_I18N = True
USE_TZ = True
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
SIMPLE_HISTORY_HISTORY_ID_USE_UUID = True
from app.settingsLocal import *
+20 -1
View File
@@ -1,6 +1,9 @@
from django.contrib.auth import get_user_model
from django.contrib.postgres.expressions import ArraySubquery
from django.db import models
from django.db.models import OuterRef
from django.db.models.fields.related import RelatedField
from django.db.models.functions import JSONObject
from app.utils.helpers import recursive_getattr
@@ -78,7 +81,23 @@ class BaseQuerySet(models.QuerySet):
for field_name, _ in self.headers().items():
fields.append(field_name)
return self.values(*fields)
if hasattr(self.model, "history"):
qs = self.annotate(
history=ArraySubquery(
self.model.history.model.objects.filter(id=OuterRef("id")).values(
json=JSONObject(
id="history_id",
date="history_date",
)
)
)
)
fields.append("history")
else:
qs = self
return qs.values(*fields)
class BaseManager(models.Manager.from_queryset(BaseQuerySet)):