homelog/container/models.py

42 lines
2.2 KiB
Python
Raw Permalink Normal View History

2022-03-09 10:33:05 +00:00
from django.db import models
2022-03-09 17:13:09 +00:00
from django.conf import settings
2022-04-11 12:24:35 +00:00
from homelog.system_user import get_deleted_user
2022-03-09 17:13:09 +00:00
class ContainerType(models.Model):
named_id = models.CharField(max_length=40, unique=True)
description = models.CharField(max_length=200)
width = models.IntegerField('width in mm')
height = models.IntegerField('height in mm')
length = models.IntegerField('length in mm')
inner_width = models.IntegerField('inner width in mm', blank=True, null=True)
inner_height = models.IntegerField('inner height in mm', blank=True, null=True)
inner_length = models.IntegerField('inner length in mm', blank=True, null=True)
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)
2022-04-11 12:24:35 +00:00
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
related_name='created_container_types')
2022-03-09 17:13:09 +00:00
changed_ts = models.DateTimeField('datetime updated', auto_now=True)
2022-04-11 12:24:35 +00:00
changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
related_name='changed_container_types')
def __str__(self):
return self.named_id + ': ' + self.description
2022-03-09 17:13:09 +00:00
class Container(models.Model):
named_id = models.CharField(max_length=40)
container_type = models.ForeignKey(ContainerType, on_delete=models.CASCADE)
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)
2022-04-11 12:24:35 +00:00
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
related_name='created_container')
2022-03-09 17:13:09 +00:00
changed_ts = models.DateTimeField('datetime updated', auto_now=True)
2022-04-11 12:24:35 +00:00
changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
related_name='changed_container')
def __str__(self):
return self.named_id + ' (' + self.container_type.named_id + '): ' + self.description