Answer the question
In order to leave comments, you need to log in
How to make order?
class Doc(models.Model):
name_doc = models.CharField("Название", max_length=150, null=True, blank=True)
files = models.FileField("Документы", upload_to = "product/documents/", null=True, blank=True)
doc_format = models.ForeignKey(Format, verbose_name='Формат файла', on_delete=models.DO_NOTHING, null=True, blank=True)
demo = models.ManyToManyField(Demo, verbose_name="Демо", on_delete=models.DO_NOTHING, null=True, blank=True)
def __str__(self):
return f'{self.name_video} - {self.name_doc}'
class Meta:
verbose_name = 'Видео и документ'
verbose_name_plural = "Видео и документы"
class Demo(models.Model):
name = models.CharField("номер стрваницы", max_length=150)
demo_img = models.ImageField("Демо изображение", upload_to="product/documents/demo/")
page_number = models.IntegerField()
doc = models.ForeignKey(Doc, verbose_name="файлы демо", on_delete=models.CASCADE)
def __str__(self):
return f'{self.name} - {self.doc}'
class Meta:
verbose_name = 'Демо просмотр'
verbose_name_plural = "Демо просмотр"
Answer the question
In order to leave comments, you need to log in
When such a desire arises, it is more like a design problem. Why is the doc field needed for Demo?
ZY even not so:
demo as ManyToManyField at Doc, it is necessary only if the same demo can be in several Docs, if it is not so, then doc as ForeignKey at Demo is enough.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question