【发布时间】:2015-11-26 14:58:19
【问题描述】:
我正在尝试获取未来 15 天内生日的人员列表。我有这个模型:
class Cliente(models.Model):
nombre = models.CharField(max_length=100)
fecha_nacimiento = models.DateField(default=datetime.date.today,blank=True,null=True)
telefono_numero = models.CharField(max_length=10, null=True)
direccion = models.CharField(max_length=100, null=True)
otro_contacto = models.CharField(max_length=150, null=True)
def __unicode__(self):
return u'%s' % self.nombre
我的字段“fecha_nacimiento”(出生日期)是一个models.DateField。当我可以使用它来获取生日在当月的人时:
mes = date.today().month
cumplen_mes = Cliente.objects.filter(fecha_nacimiento__month=mes)
我有一个查询集,在特定月份与谁生日,但我只想查看接下来 15 天内的那些生日。我尝试使用过滤器,但我不知道如何连接过滤器,即:
我可以做到Cliente.objects.filter(fecha_nacimiento__day = a_day)
我阅读了有关 gte 和 lte 的信息,但无法在 fecha_nacimiento 字段上与此过滤器结合使用。
【问题讨论】:
-
The answer on this question 可能会有所帮助。
-
非常感谢,这篇文章正是我需要的解决方案!