2

我正在尝试在 Django 中编写一个过滤器,我首先过滤查询集,然后我想再次使用以下 SQL-statemnet 过滤它:

SELECT * FROM user, 
    (select EXTRACT(year FROM age(birthday)) as age FROM user) as age 
WHERE age.age between 20 AND 40;

我怎样才能做到这一点?

编辑:模型如下

class User(models.Model):
    first_name = models.CharField(max_length=50)
    birthday = models.DateField()
4

1 回答 1

2

你知道你可以链接过滤器吗?

import datetime

now = datetime.datetime.now().year
u = User.objects.filter(x=42).filter(birthday__year__range=(now-40,now-20))
于 2013-05-07T12:57:16.757 回答