我需要使用以下句子:
qs = FamilyActivity.objects.all()
qs = qs.filter(Q(end_time__week_day__lt = F('start_time__week_day')) or Q(F('end_time')- F('start_time')>=timedelta(days=5)) or Q(end_time__week_time__gte=6))
但我不能这样做。我想搜索包括周末活动在内的未来。不能使用__week_day__lt
吗?
我的models.py:
class FamilyActivity(models.Model):
org = models.ForeignKey(Org)
name = models.CharField(verbose_name=_('name'), max_length=200)
start_time = models.DateTimeField(verbose_name=_('start_time'))
end_time = models.DateTimeField(verbose_name=_('end_time'))
cost = models.CharField(verbose_name=_('cost'), max_length=4000)
我的views.py:
def search_fa_Map(request, cat=''):
qs = FamilyActivity.objects.all()
if cat != '':
cat_ids = cat.split("-")
try :
if(len(cat_ids) >= 6):
fa_district_id = int(cat_ids[0])
fa_time_id = int(cat_ids[1])
fa_type_id = int(cat_ids[2])
fa_age_id = int(cat_ids[3])
fa_cost_id = int(cat_ids[4])
fa_state_id = int(cat_ids[5])
fa_block_id = 0
if(len(cat_ids) >= 7):
fa_block_id = int(cat_ids[6])
if fa_time_id != 0:
now = datetime.datetime.now()
oneday = datetime.timedelta(days=1)
if fa_time_id == 45:#today
qs = qs.filter(Q(start_time__lte=now,end_time__gte=now))
elif fa_time_id == 46:#weekend
qs = qs.filter(Q(end_time__week_day__lt = F('start_time__week_day')) or Q(F('end_time')-F('start_time')>=timedelta(days=5)) or Q(end_time__week_time__gte=6))
我只希望以下句子可以正常工作。
qs = qs.filter(Q(end_time__week_day__lt = F('start_time__week_day')) or Q(F('end_time')-F('start_time')>=timedelta(days=5)) or Q(end_time__week_time__gte=6))
答案 0 :(得分:1)
or
是错误的运营商。你想要|
。