KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How does one do a filter on a Django Model using a Dictionary rather than method arguments? This is what I have right here: class StoreView(TemplateView): def get(self, request): # A bunch of gets sort = request.GET.get('sort') sort_price = request.GET.get('sort_price') sort_mfr_method = request.GET.get('mfr_method') # The params tpsort by sort_params = {} if sort is not None: sort_params['sort'] = sort if sort_price is not None: sort_params['sort_price'] = sort_price if sort_mfr_method is not None: sort_params['sort_mfr_method'] = sort_mfr_method # The Model Query design_list = models.Design.objects.filter(sort_params) # etc... Side Question, is there a better way set the dictionary values than what I'm doing above? Such as a ternary, yet in a way that would make the value not exist if it's none? sort_params['sort'] = sort if not None else ''
Tags (comma-separated)
Save Edits
Cancel