Help to unite search in several models.
I have two models Apartment
and Houses
. These models have the same strings State
. According to them, I customize the search in views.py
. It looks like this:
views.py
def search(request):
queryset_list = Houses.objects.order_by('-list_date')
if 'state' in request.GET:
state = request.GET['state']
if state:
queryset_list = queryset_list.filter(state__iexact=state)
context = {
'queryset_list': queryset_list,
}
return render(request, '/search-templates/search.html', context)
As a result, I see Houses
from the selected region. I understand that the search is conducted in the model Houses
. It works great!
queryset_list = Houses.objects.order_by('-list_date')
Question:
How to combine search? Show objects from two models Apartment
and Houses
.
Thank you in advance!