28 lines
850 B
Python
Executable File
28 lines
850 B
Python
Executable File
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from rules.contrib.models import RulesModel
|
|
|
|
from outbo.apps.core.models import TimestampableDeletableMixin
|
|
from outbo.apps.final_photobriefing.enums import PhotoType
|
|
|
|
|
|
class Photo(TimestampableDeletableMixin, RulesModel):
|
|
brief = models.ForeignKey(
|
|
verbose_name=_("photo brief"),
|
|
to="Brief",
|
|
on_delete=models.CASCADE,
|
|
related_name="photos",
|
|
related_query_name="photo",
|
|
)
|
|
|
|
type = models.CharField(
|
|
max_length=50,
|
|
choices=((type, type.value) for type in PhotoType),
|
|
default=PhotoType.INVALID,
|
|
)
|
|
|
|
def filename(self, filename):
|
|
return f"projects/{self.brief.product.project.slug[1:]}/photos/{filename}"
|
|
|
|
file = models.ImageField(verbose_name=_("file"), upload_to=filename)
|