this question extends Django Pass Multiple Models to one Template
In that I want to produce 1 template, that is my profile index page, so it will list all the objects created by the user specified in the url
I want to query multiple models for one template, get the Profile in question and show all the oferto objects that was created by the attached profile
views.py
class ProfileIndex(ListView):
context_object_name = 'account_list'
template_name = 'profiles/account_index.html'
queryset = Profile.objects.all()
def get_context_data(self, **kwargs):
context = super(ProfileIndex, self).get_context_data(**kwargs)
context['profile'] = Profile.objects.all()
context['oferto'] = Oferto.objects.get(kwargs.profile.slug)
return context
urls.py I am thinking I need to get the profile slug from the url in order to search for all oferto by that user in the url
url(
regex=r"^index/(?P<slug>[-_\w]+)",
view=ProfileIndex.as_view(),
name="profile_index",
),
And this has been the hardest to figure out, how to make my template work correctly from the context in question
{% block content %}
<h1>{{ profile }}<h1>
<h2> Ofertoj or/aĆ Offers</h2>
{% for oferto in profile %}
<a href="{% url "oferto_detail" oferto.slug %}">{{ oferto.name }}</a><br/>
{% endfor %}
{% endblock %}