homelog/container/models.py

42 lines
2.2 KiB
Python

from django.db import models
from django.conf import settings
from homelog.system_user import get_deleted_user
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)
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_deleted_user),
related_name='changed_container_types')
def __str__(self):
return self.named_id + ': ' + self.description
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)
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_deleted_user),
related_name='changed_container')
def __str__(self):
return self.named_id + ' (' + self.container_type.named_id + '): ' + self.description