From 6aadef827ec16de8165cad6c81b811cf295faa98 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Mon, 11 Apr 2022 14:24:35 +0200 Subject: [PATCH] Fixed related name on auth fields --- container/models.py | 18 ++++++++++-------- homelog/system_user.py | 9 +++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 homelog/system_user.py diff --git a/container/models.py b/container/models.py index 3812443..59ff1f7 100644 --- a/container/models.py +++ b/container/models.py @@ -1,9 +1,7 @@ from django.db import models from django.conf import settings -from django.contrib.auth import get_user_model +from homelog.system_user import get_deleted_user -def get_sentinel_user(): - return get_user_model().objects.get_or_create(username='deleted')[0] class ContainerType(models.Model): named_id = models.CharField(max_length=40, unique=True) @@ -17,9 +15,12 @@ class ContainerType(models.Model): has_cover = models.BooleanField('container has a cover') contains_container = models.BooleanField('container can bear container') created_ts = models.DateTimeField('datetime created', auto_now_add=True) - created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user), related_name='created_container_types') + created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user), + related_name='created_container_types') changed_ts = models.DateTimeField('datetime updated', auto_now=True) - changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user), related_name='changed_container_types') + changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user), + related_name='changed_container_types') + class Container(models.Model): named_id = models.CharField(max_length=40) @@ -27,7 +28,8 @@ class Container(models.Model): color = models.CharField(max_length=60, blank=True) description = models.CharField(max_length=200, blank=True) created_ts = models.DateTimeField('datetime created', auto_now_add=True) - created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user), related_name='created_container') + created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user), + related_name='created_container') changed_ts = models.DateTimeField('datetime updated', auto_now=True) - changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user), related_name='changed_container') - + changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user), + related_name='changed_container') diff --git a/homelog/system_user.py b/homelog/system_user.py new file mode 100644 index 0000000..bfbbcf9 --- /dev/null +++ b/homelog/system_user.py @@ -0,0 +1,9 @@ +from django.contrib.auth import get_user_model + + +def get_system_user(): + return get_user_model().objects.get_or_create(username='system')[0] + + +def get_deleted_user(): + return get_user_model().objects.get_or_create(username='deleted')[0] \ No newline at end of file