homelog/asset/models.py

19 lines
907 B
Python

from django.db import models
from django.conf import settings
from django.contrib.auth import get_user_model
# from django.contrib.auth.models import User
from container.models import Container
def get_sentinel_user():
return get_user_model().objects.get_or_create(username='deleted')[0]
class Asset(models.Model):
named_id = models.CharField(max_length=40, unique=True)
description = models.CharField(max_length=250, blank=True)
quantity = models.IntegerField(default=1)
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_assets')
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_assets')