简体   繁体   中英

The code should filter events from the future, but it does not

I have project in old django version - 1.5 (I know better is to upated to newer version, but for now this is not an issue).

I have code connecting with pure sql - I want to have only events from the future - display on list.

Here is my code - some reason I got event from the past. I tried without MIN(date), but I got an error:

more than one row returned by a subquery used as an expression

@register.assignment_tag
def get_teasers():
    return Teaser.objects.extra(select={'next_activity': 'SELECT MIN(date) FROM productions_activity WHERE productions_activity.production_id = home_teaser.production_id'}).filter(Q(online__lte=now()), Q(online_end__gte=now()) | Q(online_end__isnull=True)).order_by('next_activity')

在句子的末尾添加.last()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM