Answer the question
In order to leave comments, you need to log in
How to read data from a videodoc model?
Models
class VideoDoc(models.Model):
...
name_doc = models.CharField("Название", max_length=150, null=True, blank=True)
files = models.FileField("Документы", upload_to = "product/documents/", 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(VideoDoc, verbose_name="файлы демо", on_delete=models.CASCADE)
def __str__(self):
return f'{self.name} - {self.doc}'
class Meta:
verbose_name = 'Демо просмотр'
verbose_name_plural = "Демо просмотр"
class VideoDoc(ListView):
model = VideoDoc
queryset = VideoDoc.objects.all()
template_name = "products/docs.html"
{% for doc in videodoc_list.all %}
<div class="product">
<div style="border: 1px solid #000000; border-radius: 5px;">
<div class="col-lg-12">
<div class="strong4" align="center" style="color: #000000;">{{ doc.name_doc }}</a> <span style="color: #019fe4;">{{ doc.files.file.size|filesizeformat }}</span>
<div class="dem" style="width: 100px; height: 100px; z-index: -1;">
{% for demo in doc.demo.all %}
<img src="{{ demo.demo_img }}" alt="">
{% endfor %}
</div>
<span>(</span><img class="img-corect" src="{% static 'images/pdf.png' %}" alt=""><span>)</span> <div align="center"><a href="{{ doc.files.url }}" download="{{ doc.files.url }}" style="color: #ff0000;">Скачать</a></div></div>
</div>
<div class="col-lg-12">
</div>
</div>
</div>
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