homelog/asset/models.py

23 lines
1.0 KiB
Python
Raw Normal View History

2022-03-10 16:28:39 +00:00
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
2022-03-16 16:43:52 +00:00
from django.urls import reverse
2022-03-10 16:28:39 +00:00
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')
2022-03-16 16:43:52 +00:00
def get_absolute_url(self):
return reverse('asset:detail', kwargs={'pk': self.pk})