A
A
AliminVerckon2020-08-22 19:38:13
Django
AliminVerckon, 2020-08-22 19:38:13

How do I put data in the default attribute from the files variable?

class VideoDoc(models.Model):
  name_video = models.CharField("Название", max_length=150, null=True, blank=True)
  poster = models.ImageField("изображение", upload_to = 'product/videos/posters/', null=True, blank=True)
  video = models.FileField("Видео", upload_to = "product/videos/", null=True, blank=True)
  name_doc = models.CharField("Название", max_length=150, null=True, blank=True)
  files = models.FileField("Документы", upload_to = "product/documents/", null=True, blank=True)
  video_accept = models.BooleanField("Это видео")
  doc_accept = models.BooleanField("Это документ")
  doc_format = models.ForeignKey(Format, verbose_name='Формат файла', on_delete=models.DO_NOTHING)
  demo_doc = models.ManyToManyField(Demo, verbose_name='Демо')


class Demo(models.Model):
  demo_img = models.ImageField("Демо изображение", upload_to="product/documents/demo/", default='')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ingco, 2020-08-22
@AliminVerckon

Write a separate function that will return the value you need, and write it in default
..., default=my_custom_func_name)
Each time you save with an empty value in the field, this function will be called.
But it's better, after saving VideoDoc, right away, just create a Demo for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question