demo-int-table/back/object/models.py

83 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
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 Element3D(models.Model):
parent = models.ForeignKey("self", on_delete=models.PROTECT, blank=True, null=True)
model_file = models.FileField(upload_to=group_based_upload_to)
name = models.CharField(max_length=255)
description = models.TextField()
def __str__(self):
return self.name
class Scene3D(models.Model):
filter_horizontal = ("elements",)
name = models.CharField(
max_length=120,
)
elements = models.ManyToManyField(Element3D)
min_distance = models.IntegerField(
validators=[MinValueValidator(1), MaxValueValidator(600)], blank=True, null=True
)
max_distance = models.IntegerField(
validators=[MinValueValidator(2), MaxValueValidator(1000)],
blank=True,
null=True,
)
hdr_gainmap = models.FileField(
upload_to=group_based_upload_to, blank=True, null=True
)
hdr_json = models.FileField(upload_to=group_based_upload_to, blank=True, null=True)
hdr_webp = models.FileField(upload_to=group_based_upload_to, blank=True, null=True)
def __str__(self):
return self.name
class ClickableArea(models.Model):
name = models.CharField("название", max_length=255)
description = models.TextField("описание")
object_name = models.CharField("название объекта", max_length=255)
target_name = models.CharField(
max_length=200,
blank=True,
null=True,
)
target = models.ForeignKey(
Scene3D,
on_delete=models.PROTECT,
related_name="clickable_areas",
blank=True,
null=True,
)
source = models.ForeignKey(
Element3D,
on_delete=models.PROTECT,
)
image = models.ImageField('Картинка', upload_to='images', blank=True, null=True)
# def image_size_validator_factory(min_w=600, min_h=600, field_name='image'):
# def validator(image):
# if image.width < min_w or image.height < min_h:
# raise ValidationError(
# {field_name: f'Размер картинки от {min_w}х{min_h} пикселей. '}
# )
def __str__(self):
return self.name