45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import uuid
|
|
from django.db import models
|
|
|
|
from tmc.models import CustomTable
|
|
|
|
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 Element(models.Model):
|
|
tmc = models.ForeignKey(CustomTable, models.RESTRICT)
|
|
name = models.CharField()
|
|
photoid = models.CharField()
|
|
photo = models.ImageField(null=True, upload_to=group_based_upload_to)
|
|
text = models.TextField(blank=True, null=True)
|
|
|
|
def __str__(self):
|
|
return f"Element {self.tmc} {self.name}"
|
|
|
|
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, unique_for_month=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
tmc = models.ManyToManyField(CustomTable)
|
|
element = models.ManyToManyField(Element)
|
|
|
|
def __str__(self):
|
|
return f"Tg item {self.id}"
|