2024-06-12 07:32:49 +00:00
|
|
|
from django.db import models
|
2024-07-09 11:35:35 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-07-18 15:21:22 +00:00
|
|
|
from utils.constants import (
|
|
|
|
STR_SM_SIZE,
|
|
|
|
STR_SIZE,
|
|
|
|
STR_EXTEND_SIZE,
|
|
|
|
)
|
2024-06-12 07:32:49 +00:00
|
|
|
|
2024-10-10 10:28:03 +00:00
|
|
|
from user.models import User, Institution
|
2024-07-19 15:40:01 +00:00
|
|
|
# from device.models import Device
|
2024-09-18 16:01:46 +00:00
|
|
|
# from evidence.models import Annotation
|
2024-07-09 11:35:35 +00:00
|
|
|
|
|
|
|
|
2024-07-18 15:21:22 +00:00
|
|
|
class LotTag(models.Model):
|
|
|
|
name = models.CharField(max_length=STR_SIZE, blank=False, null=False)
|
2024-09-18 16:01:46 +00:00
|
|
|
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
2024-10-10 10:28:03 +00:00
|
|
|
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
2024-07-18 15:21:22 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2024-07-09 11:35:35 +00:00
|
|
|
|
2024-07-19 15:40:01 +00:00
|
|
|
class DeviceLot(models.Model):
|
|
|
|
lot = models.ForeignKey("Lot", on_delete=models.CASCADE)
|
|
|
|
device_id = models.CharField(max_length=STR_EXTEND_SIZE, blank=False, null=False)
|
|
|
|
|
|
|
|
|
2024-07-18 15:21:22 +00:00
|
|
|
class Lot(models.Model):
|
2024-07-09 11:35:35 +00:00
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
updated = models.DateTimeField(auto_now=True)
|
|
|
|
name = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
|
|
|
code = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
|
|
|
description = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
2024-09-26 00:50:26 +00:00
|
|
|
closed = models.BooleanField(default=False)
|
2024-09-18 16:01:46 +00:00
|
|
|
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
2024-10-10 10:28:03 +00:00
|
|
|
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
2024-07-18 15:21:22 +00:00
|
|
|
type = models.ForeignKey(LotTag, on_delete=models.CASCADE)
|
2024-07-19 15:40:01 +00:00
|
|
|
|
|
|
|
def add(self, v):
|
|
|
|
if DeviceLot.objects.filter(lot=self, device_id=v).exists():
|
|
|
|
return
|
|
|
|
DeviceLot.objects.create(lot=self, device_id=v)
|
|
|
|
|
|
|
|
def remove(self, v):
|
|
|
|
for d in DeviceLot.objects.filter(lot=self, device_id=v):
|
|
|
|
d.delete()
|
|
|
|
|
2024-07-30 11:37:08 +00:00
|
|
|
|
|
|
|
class LotAnnotation(models.Model):
|
|
|
|
class Type(models.IntegerChoices):
|
|
|
|
SYSTEM= 0, "System"
|
|
|
|
USER = 1, "User"
|
|
|
|
DOCUMENT = 2, "Document"
|
|
|
|
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
lot = models.ForeignKey(Lot, on_delete=models.CASCADE)
|
2024-09-18 16:01:46 +00:00
|
|
|
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
2024-10-10 10:28:03 +00:00
|
|
|
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
2024-07-30 11:37:08 +00:00
|
|
|
type = models.SmallIntegerField(choices=Type)
|
|
|
|
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
|
|
|
value = models.CharField(max_length=STR_EXTEND_SIZE)
|