I've been able to implement a filtering solution for my app...so far I have filtering by year, make and body style for a vehicle inventory. What I want to do is to filter the record this way:
Lets assume I choose Acura in make, in the resultant page, if I choose one of the other filters i.e. year or body style, I'll need only the records containing Acura and the chosen year or body style.
My code for one of the filters is as below:
def year_filter(request, year):
vehicle_query = Vehicle.objects.filter(
common_vehicle__year__year__exact=year
).exclude(status__status='Incoming')
vehicle_list = vehicle_query.order_by(
'common_vehicle__series__model__manufacturer__manufacturer',
'common_vehicle__series__model__model',
'common_vehicle__year'
)
vehicle = paginate(request, vehicle_list)
year_count = vehicle_query.order_by(
'-common_vehicle__year__year')
.values('common_vehicle__year__year')
.annotate(count=Count('id')
)
make_count = vehicle_query.order_by(
'common_vehicle__series__model__manufacturer__manufacturer')
.values('common_vehicle__series__model__manufacturer__manufacturer')
.annotate(count=Count('id')
)
style_count = vehicle_query.order_by(
'common_vehicle__body_style__style')
.values('common_vehicle__body_style__style')
.annotate(count=Count('id')
)
color_count = vehicle_query.order_by(
'exterior_colour__exterior_colour')
.values('exterior_colour__exterior_colour')
.annotate(count=Count('id')
)
return render_to_response('vehicles.html', {
'vehicle': vehicle,
'make_count': make_count,
'year_count': year_count,
'style_count': style_count,
})