0

次の文を使用する必要があります。

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))
4

1 に答える 1

1

or間違った演算子です。あなたが欲しい|

于 2012-08-28T08:25:15.383 に答える