Answer the question
In order to leave comments, you need to log in
How to create a fake field in a django model?
There is a simple class
class Image(models.Model):
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
name = models.TextField(verbose_name="базовое имя изображения")
base_image = models.ImageField(verbose_name="базовое изображение")
resize_image = models.ImageField(verbose_name="изменённое изображение", blank=True, null=True)
class Meta:
verbose_name = "изображение"
verbose_name_plural = "изображения"
def __str__(self):
return self.name
def get_image(self) -> str:
if self.resize_image:
return self.resize_image
else:
return self.base_image
image = property(get_image)
, only working.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question