Skip to content

A django field to store a date with a year, a year and a month, or a year-month-day

License

Notifications You must be signed in to change notification settings

skioo/django-variable-resolution-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-variable-resolution-date

Build Status PyPI version Requirements Status License: MIT

A django field that can represent either a year, or a year and a month, or a full calendar date.

This is useful when the precision of your data varies (perhaps your legacy data only contains a year whereas you now start collecting full dates).

The representation in the database is simply a string in https://en.wikipedia.org/wiki/ISO_8601 format. This means we cannot use date-specific database operations, but we can still leverage the fact that the lexicographical order corresponds to the chronological order:

  • Sorting on a VariableResolutionDateField column will sort chronologically.
  • We can filter for dates within a range by using string operations, for instance: member_since > '2000'

Requirements

  • Python: 3.4 and over
  • Django: 1.10 and over

Usage

Install from pip:

pip install django-variable-resolution-date

Use in your models:

from django.db import models
from variable_resolution_date import VariableResolutionDateField


class ClubMember(models.Model):
    name = models.CharField(max_length=100)
    member_since = VariableResolutionDateField()

The input widget for such fields is a text field that verifies the input is valid. For instance:

  • 1996, 1996-02, 1996-02-29 are valid
  • 1997-02-29 is invalid

About

A django field to store a date with a year, a year and a month, or a year-month-day

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages