用于处理生日的助手字段和管理器
django-birthda的Python项目详细描述
Django Birthday是一个帮助库,用于处理模型中的生日。
作者是Jonas Obrist,一些伟大的 contributors。
安装
pip install django-birthday
用法
django birthday提供了一个birthday.fields.BirthdayField模型 字段类型,它是django.db.models.DateField和 因此也有同样的特点。它还在内部添加了 第二个领域,你的模型举行了一年中的一天 生日,这用于 birthday.managers.BirthdayManager应该用作 你的模特经理。
模型可能是这样的:
fromdjango.dbimportmodelsimportbirthdayclassUserProfile(models.Model):user=models.ForeignKey('auth.User')birthday=birthday.fields.BirthdayField()objects=birthday.managers.BirthdayManager()
在未来30天内获取所有用户配置文件:
UserProfile.objects.get_upcoming_birthdays()
获取所有今天生日的用户配置文件:
UserProfile.objects.get_birthdays()
或根据用户的生日订购用户配置文件:
UserProfile.objects.order_by_birthday()
有关更多详细信息,请参阅阅读文档中的documentation。
许可证
django-birthday是根据bsd许可证发布的。