So what I'm trying to do is pass another model object (Question) to my view.The view currently returns a get_queryset
of another model (Post). So this is the context I want to pass through so I can render it in my polls.html
:
question = get_object_or_404(Question, id=1)
context = {'question': question})
urls.py
BV = BoxesView.as_view()
urlpatterns = [
url(r'^$', BV, name='news')
]
view.py
class BoxesView(ListView):
template_name = 'polls.html'
def get_queryset(self):
queryset_list = Post.objects.all().filter(category=1).order_by('-date')
return queryset_list
polls.html
{% extends 'parent.html' %}
{% block polls %}
<p>question goes here</p> #this shows up
{{ question.question_text }} #this doesn't show up
{% endblock %}
parent.html
{% extends 'base.html' %}
{% block content %}
{% for post in post_list %}
{% block polls %}
{% endblock %}
{% endfor %}
{% endblock %}
models.py
class Post(models.Model):
title = models.TextField(max_length=70)
class Question(models.Model):
question_text = models.CharField(max_length=70)