Provides a Django model and form fields for dates that do not include years.
One use case is to collect birthdays without requiring the year of birth.
Prerequisites
Django 1.8 - 1.11, 2.0
Python 2.7, 3.6
(Other versions may function, but are untested.)
Installation
pip install django-yearlessdate
Usage
The package provides two model fields, YearlessDateField and YearField.
YearlessDateField
YearlessDateField stores a date without a year: January 1st, for example.
Its default widget consists of two dropdowns, one for a day and one for the month.
It will only allow potentially valid dates. For example, a user won’t be able to set the date to April 31st. February 29th is counted as a valid date.
Here’s an example models.py that declares a model with a required yearless date:
from django.db import models
from djangoyearlessdate.models import YearlessDateField
class MyModel(models.Model):
birthday = YearlessDateField()
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>]
YearField
YearField is a very simple model field that stores the year as an integer, and ensures the year provided lies between 1900 and 2200:
from django.db import models
from djangoyearlessdate.models import YearField
class MyModel(models.Model):
year = YearField(null=True, blank=True)
Use of YearField is not recommended due to its lack of configurability. You’re almost certainly better of using a SmallIntegerField in combination with a MinValueValidator and a MaxValueValidator.
Running tests
Setup
Ensure you have a recent version of tox installed.
Clone this repo.
Running tests
From the root of this repo, simply run:
tox
Metadata
Release files for django-yearlessdate 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-yearlessdate-1.3.1.tar.gz | 4.6 kB | Without provenance | Details |
Release files / django-yearlessdate-1.3.1.tar.gz
| Download URL | django-yearlessdate-1.3.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03dfa9f7e0267ed05015896e698a81df982b68c203ec5256565897d0578e08b0
|
|
BLAKE2b-256 checksum How to use checksums |
4063f4b7c02b6662e152025710e90e110660c116db40c95e469b6c2e885bbeeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1
|
Security for django-yearlessdate 1.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.