I am working on a legacy code that uses django basic apps. The basic blog app has tag results page.
I would like to know how can I extend this method to return tagged content from two models. The Post model and some other model.
def tag_detail(request, slug, template_name='blog/tag_detail.html', **kwargs):
tag = get_object_or_404(Tag, name__iexact=slug)
return list_detail.object_list(
request,
queryset=Post.objects.filter(tags__name__iexact=slug, status=2),
extra_context={'tag': tag},
template_name=template_name,
**kwargs
)
EDIT
Here is what I ended up doing
quertsetA = A.objects.filter(tags__name__iexact=slug, status=2)
querysetB = B.objects.filter(tags__name__iexact=slug, status=2)
result_list = list(chain(quertsetA, querysetB))
This works in the python shell but only quertsetA’s values are being passed to the template.
Here is the relevant part of the view
return list_detail.object_list(
request,
queryset=result_list,
template_name=template_name,
**kwargs
)
And template
{% for post in object_list %}
{{ post }}
{% endfor %}
If you convert the querysets to lists then you can just concatenate them