Skip to main content

django_partial_date

Django custom model field for partial dates with the form YYYY, YYYY-MM, YYYY-MM-DD

  • Works with DRF
  • Supports comparison operations
  • Supports Django versions 2.0, 3.0 and 4.0

Usage

install the package

pip install django_partial_date

partial_date.PartialDateField

A django model field for storing partial dates. Accepts None, a partial_date.PartialDate object, or a formatted string such as YYYY, YYYY-MM, YYYY-MM-DD. In the database it saves the date in a column of type DateTimeField and uses the seconds to save the level of precision.

class partial_date.PartialDate

Object to represent the partial dates.

Example

models.py

from django.db import models
from partial_date import PartialDateField

class TestModel(models.Model):
    some_partial_date = PartialDateField()
>>> from partial_date import PartialDate
>>> from core.models import TestModel
>>> obj = TestModel(some_partial_date="1995")
>>> obj.save()
>>> obj.some_partial_date
'1995'
>>> obj.some_partial_date = PartialDate("1995-09")
>>> obj.save()
>>> obj.some_partial_date
1995-09
>>>
>>> from partial_date import PartialDate
>>> import datetime
>>> partial_date_instance = PartialDate(datetime.date(2012, 9, 21), precision=PartialDate.DAY)
>>> partial_date_instance
2012-09-21
>>> partial_date_instance.precisionYear()
False
>>> partial_date_instance.precisionMonth()
False
>>> partial_date_instance.precisionDay()
True
>>> partial_date_instance.precision == PartialDate.YEAR
False
>>> partial_date_instance.precision == PartialDate.MONTH
False
>>> partial_date_instance.precision == PartialDate.DAY
True
>>> partial_date_instance.precision = PartialDate.MONTH
>>> partial_date_instance
2012-09
>>> partial_date_instance = PartialDate("2015-11-01")
>>> partial_date_instance.date
datetime.date(2015, 11, 1)
>>> from partial_date import PartialDate
>>> partial_date_instance = PartialDate("2015-11-01")
>>> partial_date_instance
2015-11-01
>>> partial_date_instance.format('%Y', '%m/%Y', '%m/%d/%Y') # .format(precision_year, precision_month, precision_day)
'11/01/2015'
>>> partial_date_instance = PartialDate("2015-11")
>>> partial_date_instance
2015-11
>>> partial_date_instance.format('%Y', '%m/%Y', '%m/%d/%Y')
'11/2015'
>>> partial_date_instance = PartialDate("2015")
>>> partial_date_instance
2015
>>> partial_date_instance.format('%Y', '%m/%Y', '%m/%d/%Y')
'2015'

Thanks for their collaborations to

  • lorinkoz
  • howieweiner
  • jghyllebert
  • sorinmarti

Metadata

Release files for django-partial-date 1.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-partial-date 1.3.2
File Size Uploaded
django_partial_date-1.3.2.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-partial-date 1.3.2
File Interpreter ABI Platform
django_partial_date-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / django_partial_date-1.3.2.tar.gz

Download URL django_partial_date-1.3.2.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
07bc97c04e7fbce8803f2a95723b508c726e466c175874985c5568b29f6ff893
BLAKE2b-256 checksum
How to use checksums
4e630d6198422a5b4a32f600bc595130817f9c8074d02c3b8d81202e1f3fdc35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release files / django_partial_date-1.3.2-py3-none-any.whl

Download URL django_partial_date-1.3.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8243ce1f9062e36d217a630c15a1436c419b3949799754f8cefb403b17d59fb4
BLAKE2b-256 checksum
How to use checksums
76c8f0b5ac20a68c168e1ca5ac6755f7c2b96242992fcb2b2b63c2aadb5fa278
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page