view:
class ArticleVifania(ListView): model = Article template_name = "blog/articles.html" context_object_name = "my_favorit_publisher" def get_context_data(self, **kwargs): context = super(ArticleVifania, self).get_context_data(**kwargs) context[ "insert" ] = AddCodeYoutube.objects.all()[0] return context
models:
class AddCodeYoutube(models.Model): name_pole = models.CharField(max_length=100, blank=True) add_youtube = models.CharField(max_length=300, verbose_name='Добавить код с YouTube') def __unicode__(self): return "%s" % self.name_pole class Article(models.Model): title = models.CharField(max_length=100) content = models.TextField() date = models.DateTimeField(auto_now=False) article_tag = models.ForeignKey(Tag) video = models.ForeignKey(AddCodeYoutube) def __unicode__(self): return "Заголовок статьи %s" % self.title
Шаблоныч:
{% block content %} <h2>Publishers</h2> <ul> {% for publisher in my_favorit_publisher %} <li>{{ publisher.title }} </li> <!-- Браузером обрабатывается ЮТУБ код --> <li>{{ publisher.content }} </li> <li>{{ publisher.date }} </li> <li>{{ insert.add_youtube|safe|escape }} </li> {% endfor %} </ul> {% endblock %}