【发布时间】:2018-01-20 06:53:47
【问题描述】:
我有一个表 AvailableDates,其中有一列 date 用于存储日期信息。 我想在对日期执行一些操作后过滤日期,该操作由 convert_date_to_type 函数定义,该函数采用用户提供的参数 input_variable。
def convert_date_to_type(date,input_variable):
#perform some operation on date based on input_variable
#return value will be a type, which will be any one item from types list below
return type
类型列表:
types = []
types.append('type1')
types.append('type2')
types.append('type3')
现在我想根据类型过滤表格。我将在 for 循环中执行此操作:
for i in range(0,len(types)):
#filter table here based on types[i], something like this
AvailableDates.objects.filter(convert_date_to_type(date,input_variable)=types[i])
我怎样才能做到这一点?非常感谢任何其他方法。
我无法将type信息存储在单独的列中,因为根据用户给出的input_variable,一个日期可以是不同的类型。
【问题讨论】:
标签: python django django-models django-queryset django-filters