跳转到主要内容

生日辅助字段和管理器

项目描述

django-birthday 是一个用于在模型中处理生日的辅助库。

Jonas Obrist 编写,并有一些优秀的 贡献者

https://img.shields.io/pypi/v/django-birthday.svg https://img.shields.io/pypi/dm/django-birthday.svg https://img.shields.io/github/license/bashu/django-birthday.svg https://img.shields.io/travis/bashu/django-birthday.svg

安装

pip install django-birthday

使用

django-birthday 提供了一个 birthday.fields.BirthdayField 模型字段类型,它是 django.db.models.DateField 的子类,因此具有相同的特征。它还内部为您的模型添加了一个字段,用于存储该生日的年中的日期,这用于 birthday.managers.BirthdayManager 提供的额外功能,您应将其用作模型的经理。

一个模型可能看起来像这样

from django.db import models
from django.conf import settings

from birthday import BirthdayField, BirthdayManager


class UserProfile(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    birthday = BirthdayField()

    objects = BirthdayManager()

获取未来30天内所有用户资料

UserProfile.objects.get_upcoming_birthdays()

获取今天生日的所有用户资料

UserProfile.objects.get_birthdays()

或按生日顺序排列用户资料

UserProfile.objects.order_by_birthday()

有关更多详细信息,请参阅 Read The Docs 上的文档

许可证

django-birthday 采用 BSD 许可证发布。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

django-birthday-0.1.4.tar.gz (4.8 kB 查看哈希)

上传时间:

构建分布

django_birthday-0.1.4-py3-none-any.whl (7.8 kB 查看哈希)

上传时间: Python 3

由以下支持