if(filter[0][0]):
films_material_PP = GlassFilm.objects.filter(f_material = 'PP')
else:
films_material_PP = GlassFilm.objects.none()
if(filter[0][1]):
films_material_PVC = GlassFilm.objects.filter(f_material = 'PVC')
else:
films_material_PVC = GlassFilm.objects.none()
if(filter[1][0]):
films_color_Grey = GlassFilm.objects.filter(f_color = 'Grey')
else:
films_color_Grey = GlassFilm.objects.none()
if(filer[1][1]):
films_color_Yellow = GlassFilm.objects.filter(f_color = 'Yellow')
else:
films_color_Yellow = GlassFilm.objects.none()
films_material.union(films_material_PP,films_material_PVC)
films_color.union(films_color_Grey,films_color_Yellow)
films_total.intersect(films_material,films_color)
How can we implement the last three statements in Django? I have seen other questions like this and please note that I am not looking for
GlassFilm.objects.filter((Q(f_material = 'PP') | Q(f_material = 'PVC')) & (Q(f_color = 'Grey')|Q(f_color = 'Yellow')))
*EDIT:*Here is I what I want to achieve. I provide a user with HTML-checkboxes of two types (1) Material (2) Color
In Material there are two options "PP" and "PVC" that a user might tick. Similarly there are two checkboxes in Color ("Grey" and "Yellow") that a user might tick. If a user ticks "PP" and "Grey" I want to display the objects having both of those two properties. If a user ticks only "PP" I want to display only those objects whose material is "PP". If a user ticks both "PP" and "PVC" then I want to display those objects which have material as either "PP" or "PVC".
It is for this purpose that I would like a code equivalent to the above code. Now the union()
and intersect()
functions are just pseudo-code for which I really want proper django/python code.