49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
import uuid
|
|
from django.db import models
|
|
|
|
from tmc.models import CustomTable, BaseCustomField, TerritoryItem
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger("root")
|
|
|
|
|
|
def group_based_upload_to(instance, filename):
|
|
logger.info(instance)
|
|
return "files/image/{}/{}/{}".format(
|
|
type(instance).__name__.lower(), instance.id, filename
|
|
)
|
|
|
|
|
|
class TmcField(models.Model):
|
|
field = models.ForeignKey(BaseCustomField, models.RESTRICT)
|
|
text = models.CharField(null=True, blank=True)
|
|
file_id = models.CharField(null=True, blank=True)
|
|
image_aws_url = models.CharField(null=True, blank=True)
|
|
|
|
|
|
class TmcElement(models.Model):
|
|
tmc = models.ForeignKey(CustomTable, models.RESTRICT)
|
|
name = models.CharField(null=True, blank=True)
|
|
field = models.ManyToManyField(TmcField)
|
|
|
|
|
|
class TgItem(models.Model):
|
|
id = models.UUIDField(
|
|
# auto_created=True,
|
|
primary_key=True,
|
|
default=uuid.uuid4,
|
|
editable=False,
|
|
unique=True,
|
|
)
|
|
user_id = models.BigIntegerField()
|
|
name = models.CharField(max_length=255)
|
|
location = models.ForeignKey(TerritoryItem, models.RESTRICT)
|
|
created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
|
|
updated_at = models.DateTimeField(auto_now=True, null=True, blank=True)
|
|
tmc = models.ManyToManyField(TmcElement)
|
|
|
|
def __str__(self):
|
|
return f"Tg item {self.name}"
|
|
|