Fixed related name on auth fields

This commit is contained in:
Dirk Jahnke 2022-04-11 14:24:35 +02:00
parent 056317a340
commit 6aadef827e
2 changed files with 19 additions and 8 deletions

View File

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

9
homelog/system_user.py Normal file
View File

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