Django field for storing dates without years.
Project description
Provides a Django model and form fields for dates that do not require years.
One use case is to collect birthdays without requiring the year of birth.
Prerequisites
Django 1.8 - 1.11
Python 2.7
(Other versions may be supported, but are untested.)
Installation
pip install django-yearlessdate
Usage
The package provides two model fields, YearlessDateField and YearField.
YearlessDateField provides dropdowns for day and month, and will validate accordingly. For example, a user won’t be able to set the date to April 31st. The YearField is a very simple field that just ensures the year provided lies between 1900 and 2200. (This range will become user configurable at some point.)
Here’s an example models.py that declares a model with a required yearless date and an optional year:
from django.db import models from djangoyearlessdate.models import YearlessDateField, YearField class MyModel(models.Model): birthday = YearlessDateField() year = YearField(null=True, blank=True)
The values of YearlessDateField on the model instances can be accessed like so:
>>> a = MyModel.objects.get(id=1) >>> a <MyModel: 4 August 2011> >>> a.birthday.day 4 >>> a.birthday.month 8 >>> print a.birthday 4 August
They can also be compared or sorted as would be expected, for example:
>>> m = MyModel.objects.all() >>> m [<MyModel: 4 August 2011>, <MyModel: 30 June 2013>] >>> m[0].birthday > m[1].birthday True >>> m.order_by('birthday') [<MyModel: 30 June 2013>, <MyModel: 4 August 2011>]
Tests
Setup:
Ensure you have a recent version of tox installed.
Clone this repo.
Running tests:
From the root of this repo, run:
tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_yearlessdate-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5571d353352e99a5fd0638f34288013a7134f191ee0c7c01aecc66f020aca67 |
|
MD5 | c4b3e0bd5751d6bd1e7fbf722548b654 |
|
BLAKE2b-256 | d9dd47ce3714372b74da0826450e3d0559d94a9955d316a24d70c006b5d2da32 |