homelog/asset/models.py

26 lines
1.1 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
2022-03-17 06:21:38 +00:00
2022-03-10 16:28:39 +00:00
def get_sentinel_user():
return get_user_model().objects.get_or_create(username='deleted')[0]
2022-03-17 06:21:38 +00:00
2022-03-10 16:28:39 +00:00
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)
2022-03-17 06:21:38 +00:00
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user),
related_name='created_assets')
2022-03-10 16:28:39 +00:00
changed_ts = models.DateTimeField('datetime updated', auto_now=True)
2022-03-17 06:21:38 +00:00
changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user),
related_name='changed_assets')
2022-03-10 16:28:39 +00:00
2022-03-16 16:43:52 +00:00
def get_absolute_url(self):
return reverse('asset:detail', kwargs={'pk': self.pk})