Hi,
I'd like to set up a filter in my app...I'd like to have my filters being done in increments, kinda like what is running at this site. So far my filter views are separate (is there a way of combining the filtering logic into one view?) and I'm supposing I'll need some way of saving the chosen filter (possibly sessions...but I'm not sure how to do this). My code 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, 'color_count': color_count,})
def make_filter(request, make):
vehicle_query = Vehicle.objects.filter(common_vehicle__series__model__manufacturer__manufacturer=make).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'))
series_count = vehicle_query.order_by('common_vehicle__series__series').values('common_vehicle__series__series').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, 'series_count': series_count, 'year_count': year_count, 'style_count': style_count, 'color_count': color_count,})
def series_filter(request, model):
vehicle_query = Vehicle.objects.filter(common_vehicle__series__series=model).exclude(status__status='Incoming')
vehicle_list = vehicle_query.order_by('common_vehicle__series__series', '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, 'color_count': color_count,})
def body_filter(request, body):
vehicle_query = Vehicle.objects.filter(common_vehicle__body_style__style=body).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, 'color_count': color_count,})
def color_filter(request, color):
vehicle_query = Vehicle.objects.filter(exterior_colour__exterior_colour=color).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, 'color_count': color_count,})