Answer the question
In order to leave comments, you need to log in
How to pass two tables from models.py to html template?
views.py
def music(request):
album = Music.objects.all()
context = {"album": album}
return render(request, 'main/music.html', context=context)
class Music(models.Model):
name = models.CharField(max_length=60, verbose_name="название альбома")
year = models.CharField(max_length=60, verbose_name="год выпуска", blank=True, default='')
img = models.ImageField(verbose_name="картинка", upload_to="media/imgs", null=True, default='')
music = models.CharField(max_length=60, verbose_name="ссылка", default='')
def __str__(self):
return self.name
class Music2(models.Model):
name = models.CharField(max_length=60, verbose_name="название альбома 2 колонки")
year = models.CharField(max_length=60, verbose_name="год выпуска", blank=True, default='')
img = models.ImageField(verbose_name="картинка", upload_to="media/imgs", null=True, default='')
music = models.CharField(max_length=60, verbose_name="ссылка", default='')
def __str__(self):
return self.name
Answer the question
In order to leave comments, you need to log in
The same as one, through the context:
def music(request):
album = Music.objects.all()
album2 = Music2.objects.all()
context = {"album": album,"album2": album2}
return render(request, 'main/music.html', context=context)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question