это models.py
class Articles(models.Model): name=models.CharField("Название статьи",max_length=200) text=models.TextField(verbose_name="Текст") def user_directory_foto(instance, filename): return 'foto/aticlf_{0}/{1}'.format(instance.aticlf.id, filename) class Foto(models.Model): aticlf=models.ForeignKey(Articles,on_delete=models.CASCADE,related_name='foto_articles') podp=models.CharField('Подпись',max_length=550,blank=True,null=True) foto=models.FileField('Само фото',upload_to=user_directory_foto)
app_name='core' urlpatterns = [ path('detail/<int:id>', views.detail_page, name='detail_page'), ]
[code html]
<h1>{{get_article.name}}</h1>
<p>{{get_article.text}}</p>
Прикреплённые фото
{%for tem in get_article.foto_articles.all%}
<img href="{{MEDIA_URL}}{{tem.foto}}"/>
<br>
{%endfor%}
[/code]