- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 Python 检查学生的生日是今天还是明天。在每个循环中,即使我将 DOB 列更改为今天,生日也不是今天。我该如何解决这个问题?下面是代码。
def Birthday_alert():
students= Students.objects.all()
tmr= dt.date.today()+ dt.timedelta(days=1)
tmr_bdays=[]
to_bays=[]
# verifying if date of today is working or not
for m in students:
if m.dob == dt.date.today():
print(m.name)
# putting into dictionary
for s in students:
if s.dob == dt.date.today():
to_bays.append({
'name': 's.name',
'course': 's.course.class_name',
'dob' : 's.dob',
'contact': 's.parent_contact',
})
elif s.dob + dt.timedelta(days=1) == tmr:
tmr_bdays.append({
'name': 's.name',
'course': 's.course.class_name',
'dob' : 's.dob',
'contact': 's.parent_contact',
})
else:
for m in students:
print("else:",m.name)
return (tmr_bdays,to_bays)
class Students(models.Model):
created_by = models.ForeignKey(
User, on_delete=models.SET_NULL, default=1, null=True)
name = models.CharField(max_length=200, null=True)
dob = models.DateField(null=True, verbose_name='Date of Birth')
age = models.IntegerField()
grade_choice = (
('G1', 'Grade-1'),
('G2', 'Grade-2'),
('G3', 'Grade-3'),
('G4', 'Grade-4'),
('G5', 'Grade-5'),
('G6', 'Grade-6'),
('G7', 'Grade-7'),
('G8', 'Grade-8'),
('G9', 'Grade-9'),
('G10', 'Grade-10'),
('G11', 'Grade-11'),
('G12', 'Grade-12'),
)
gender_choice=(
('M', 'Male'),
('F', 'Female'),
('N', 'None'),
)
blood_choice=(
('O', 'O'),
('A-', 'A-'),
('B+', 'B+'),
('B-', 'B-'),
('A+', 'A+'),
('AB', 'AB'),
)
relation_choice=(
('Uncle', 'Uncle'),
('Aunty', 'Aunty'),
('Father', 'Father'),
('Mother', 'Mother'),
('Grandpa', 'Grandpa'),
('Grandma', 'Grandma'),
('Sister', 'Sister'),
('Brother', 'Brother'),
)
gender=models.CharField(choices=gender_choice, max_length=10, null=True)
grade = models.CharField(choices=grade_choice, max_length=10, null=True)
attending_school = models.CharField(max_length=100, null=True)
course = models.ForeignKey(
Create_Class, on_delete=models.SET_NULL, default=1, null=True)
address = models.TextField(null=True)
parent_name = models.CharField(max_length=200, null=True)
parent_contact = models.CharField(max_length=20, null=True)
parent_address = models.TextField(null=True)
emerg_name = models.CharField(max_length=200, null=True, verbose_name='Emergency Name')
emerg_contact = models.CharField(max_length=20, null=True, verbose_name='Emergency Contact')
emerg_relation = models.CharField(choices=relation_choice ,max_length=20, null=True, verbose_name='Emergency Relationship')
doc_name = models.CharField(max_length=200, null=False, default='None', verbose_name='Doctor Name')
doc_contact = models.CharField(max_length=20, null=False, default='None', verbose_name='Doctor Contact')
blood_type = models.CharField(choices=blood_choice,max_length=10, null=True)
allergic = models.TextField(null=True)
我的期望是知道今天和明天有哪些学生生日!您的帮助将不胜感激。谢谢!
最佳答案
from datetime import timedelta
from django.utils import timezone
datetime_now = timezone.now()
now_day, now_month = datetime_now.day, datetime_now.month
datetime_tomorrow = datetime_now + timedelta(days=1)
tomorrow_day, tomorrow_month = datetime_tomorrow.day, datetime_tomorrow.month
birth_day_today = Students.objects.filter(<b>dob__day=now_day, dob__month=now_month</b>)
birth_day_tomorrow = Students.objects.filter(<b>dob__day=tomorrow_day, dob__month=tomorrow_month</b>)
关于python - 如何检查 django 中的生日是否是明天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61338711/
如果我在 forms.py 中有: birthdate = forms.DateTimeField() 和 html: 我需要创建一个新的小部件还是有答案?
我正在尝试从 facebook sdk 获取生日,我可以获取我的生日,但我无法从其他帐户获取生日。我已经在“设置”中设置了联系人电子邮件,并在此处回答了一个应用程序供公众使用:Set up app p
我需要存储用户的出生日期。我在前端创建了一个表单,通过 3 个选择下拉菜单获取他们的出生日期年、月和日。我目前将这三个值存储在 SQL 中,并具有相同名称的列。 我需要执行的查询之一是获取高于或低于特
我有 mysql 数据库,以生日列作为日期。 保存到此列的最佳方式是什么,年份是可选的。我应该随便放一些年份吗?在数据库中保存生日的最佳做法是什么。 我在 cakephp 中创建了 3 个文本字段,日
考虑到此代码(基于 Python/Mongoengine),我知道如何找到下一个即将到来的生日 class User(mongoengine.Document): (...) birthday
在以前版本的 Prestashop 1.6 中,注册表单有生日字段的日期选择器和一个下拉列表,我们可以在其中选择月、日、年。 Prestashop 版本 1.6 - 生日截图: 然后在最新版本的Pre
我正在使用带有changeYear 的jquery ui datepicker。问题是它以 block 的形式显示年份(从 1985 年到 2005 年,然后单击 1985 年打开其他年份)我需要显示
我正试图在来自佛蒙特州和纽约的成员(member)的生日表中找到最年长的人。我的成员类似于以下内容: Members ------- MemberID, Firstname, Lastname, Bi
工作中需要用到身份证验证,还要支持检查15位和18位。 我一时手懒,问同事有没有现成的函数可用,同事google了一下,扔给我一个 asp-vbscript版本的函数。 可我这边是客户端j
我正在努力解决以下正则表达式: \b[\dBb][-. \dEe]+(\d{4})\b 它应该匹配帐号,但不匹配 token /生日或其中包含“be”的文本。在 community 的支持下,我成功捕
我有一个简单的小部件,它有: 请注意,今天是生日。因此,它意味着保持相同,无论您身在何处(不应该发生时区)。如果您 1 月 10 日凌晨 3:00 出生在英国,并且在纽约查看您的个人信息,您应该仍然
在我的数据库中,日期存储为 dd/mm/yyyy。当我检索它时,我想将日期分别拆分为字符串日、字符串月和字符串年。我应该怎么做? “/”将是分隔符,对吗? 最佳答案 您需要可以使用DateTime.P
我很难通过 Facebook SDK 获取用户信息。 我正在努力争取生日、工作和教育。 我正在使用这个: let graphRequest : FBSDKGraphRequest = FBSDKGr
我正在尝试使用 NSSortDescriptor 按日期对 NSMutableArray *friends, key:birthday 进行排序,我的 NSLog 中的所有生日都为空,但名称仍在记录中
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在尝试从其 Google Plus 帐户获取用户的信息,包括性别和年龄。由于这些字段可能是私有(private)的,我认为明确请求它们可以解决问题。然而,尽管登录对话框明确指出该应用程序请求查看您
我正在制作一个 facebook 应用程序来显示用户的生日......... 'YOUR_APP_ID', 'secret' => 'Y
我正在尝试将 OAuth2 登录添加到我基于 Node/ExpressJS/MongoDB/PassportJS 构建的应用中。 我用这个方法可以成功登录,但是我无法获取某些信息。我唯一能够访问的是
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我无法让我的代码来获取我的测试帐户的“生日”,甚至我自己的“生日”(任何地方都没有成功!)来回显,尽管从我所看到的来看,我正在正确地请求它并且我拥有适当的权限对于“user_birthday”。 但是
我是一名优秀的程序员,十分优秀!