A
A
AliminVerckon2020-10-16 19:04:08
Django
AliminVerckon, 2020-10-16 19:04:08

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 = "Демо просмотр"


Views
class VideoDoc(ListView):
  model = VideoDoc
  queryset = VideoDoc.objects.all()
  template_name = "products/docs.html"


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>

Why the picture is not displayed from the Demo model

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-10-16
@AliminVerckon

Because you do not read the docks, ZY who taught you to formulate the question, in the title one, in the body of the other. {{ demo.demo_img.url }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question