B
B
bayko042020-10-03 10:09:33
Django
bayko04, 2020-10-03 10:09:33

CANNOT output 2 ForeignKeys?

I want to display ForeignKey from the model

class MangaChapters(models.Model):
    name = models.CharField("Название", max_length=100)
    ChaptersNumber = models.PositiveSmallIntegerField("Глава", default=0)
    tom = models.ForeignKey(MangaToms, verbose_name="Том", on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = 'Глава'
        verbose_name_plural = 'Главы'


which is tied to

class MangaToms(models.Model):
    name = models.CharField("Название", max_length=100)
    TomsNumber = models.PositiveSmallIntegerField("Глава", default=0)
    Manga = models.ForeignKey(MangaV, verbose_name="Манга", on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = 'Том'
        verbose_name_plural = 'Том'


Views.py file

def osamu(request, slug):
    manga = MangaV.objects.get(url=slug)
    context = {
        'pr': manga
    }
    return render(request, 'haikyuu/Manga-Full.html', locals())


html

<div class="col-md-6">
                    <button class="accordion">Показать главы</button>
                    <div class="panel">
                        <ul class="tom">
                            {% for TomsNumber in manga.mangatoms_set.all %}
                                <h2 class="chapter-number">Глава {{ TomsNumber.TomsNumber }}</h2>
                            {% endfor %}


Вот она не выводится>
                            {% for MangaChapters in mangaG.mangachapters_set.all %}
                                <li class="chapter">
                                    <a href="">{{ name.name }}</a>
                                </li>
                            {% endfor %}




                        </ul>
                    </div>
                </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-10-03
@bacon

1. What kind of nonsense is this: attach manga to pr, then use locals, and use manga in the template? Who taught you this, beat him with your feet.
2. where does mangaG appear in the template?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question