django-birthday provides a
birthday.fields.BirthdayField model field
type which is a subclass of
django.db.models.DateField and thus has the
same characteristics as that. It also internally adds a second field to your
model holding the day of the year for that birthday, this is used for the extra
functionality exposed by
birthday.managers.BirthdayManager which you
should use as the manager on your model.
A model could look like this:
from django.db import models from django.conf import settings import birthday class UserProfile(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) birthday = birthday.fields.BirthdayField() objects = birthday.managers.BirthdayManager()
Get all user profiles within the next 30 days:
Get all user profiles which have their birthday today:
Or order the user profiles according to their birthday:
Returns a queryset containing objects that have an upcoming birthday.
- days – Optional. Amount of days that still count as ‘upcoming’, defaults to 30.
- after – Optional. Start day to use, defaults to ‘today’.
- include_day – Optional. Include the ‘after’ day for lookups.
- order – Optional. Whether the queryset should be ordered by birthday, defaults to True.
- reverse – Optional. Only applies when order is True. Apply reverse ordering.
Returns a queryset containing objects which have the birthday on a specific day.
Parameters: day – Optional. What day to get the birthdays of. Defaults to ‘today’. Return type: Instance of
Returns a queryset ordered by birthday (not age!).
Parameters: reverse – Optional. Defaults to False. Whether or not to reverse the results. Return type: Instance of