gpt4 book ai didi

python - 如何使用django获取两个日期之间的生日列表

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:00 25 4
gpt4 key购买 nike

<分区>

我正在尝试获取生日在未来 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)

我有一个查询集,which birthday in a specific month,但我只想查看接下来 15 天内的那些生日。我尝试使用过滤器,但我不知道如何连接过滤器,即:

我可以做到 Cliente.objects.filter(fecha_nacimiento__day = a_day)

我阅读了有关 gte 和 lte 的内容,但无法在 fecha_nacimiento 字段上与此过滤器结合使用。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com