I would like to create a method that returns the Django ORM FILTER parameters. I will have to use these filters at different times, I would like to create this generic method. Here's the example:
def home(selected_page=None):
_config = Config.objects.filter()
_config = _config.filter(filter_config_by_page(selected_page))
return _config
def filter_config_by_page(selected_page):
final_tuple = ()
if selected_page == "work":
final_tuple = (works__user__isnull = False,)
elif selected_page == "not-work":
final_tuple = (works__user__isnull = True,)
elif selected_page == "solved":
final_tuple = (status = 2,)
elif selected_page == "not-solved":
final_tuple = (status = 3,)
return final_tuple
Error
File "/myapp/configuerson/controller/configs.py", line 101
final_tuple = (works__user__isnull = False,)
^
SyntaxError: invalid syntax
I believe, according to the error that has appeared, that I can not assign value to tuples that I am creating in this way. Would there be any way to make filter_config_by_page
work by following this logic that I described?