Can I filter a queryset based on a model field’s choices?
model:
COLORS = (
('BLACK', 'black'),
('RED', 'red'),
('BLUE', 'blue'),
//etc..
)
class Thing(Models.model):
color = models.CharField(max_length=5, choices=COLORS)
view:
def filter_by_color(request):
q = Thing.objects.filter(???)
Is there a way to filter Thing based on different color choices? Also, is there a way to write this dynamically, so that all color choices can respond to a single view?
Do you want this?
view
So when you access
http://yoursite/thisview/blackyou will getThings with black color and when you accesshttp://yoursite/thisview/redyou will getThings with red color .