r-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
Django 3.0 support.
Usage
Install the package
pip install r-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 = PartialDate(datetime.date(2012, 9, 21), precision=PartialDate.DAY)
>>> partial_date
2012-09-21
>>> partial_date.precisionYear()
False
>>> partial_date.precisionMonth()
False
>>> partial_date.precisionDay()
True
>>> partial_date.precision == PartialDate.YEAR
False
>>> partial_date.precision == PartialDate.MONTH
False
>>> partial_date.precision == PartialDate.DAY
True
>>> partial_date.precision = PartialDate.MONTH
>>> partial_date
2012-09
>>> partial_date = PartialDate("2015-11-01")
>>> partial_date.date
datetime.date(2015, 11, 1)
>>> from partial_date import PartialDate
>>> partial_date = PartialDate("2015-11-01")
>>> partial_date
2015-11-01
>>> partial_date.format('%Y', '%m/%Y', '%m/%d/%Y')
'11/01/2015'
>>> partial_date = PartialDate("2015-11")
>>> partial_date
2015-11
>>> partial_date.format('%Y', '%m/%Y', '%m/%d/%Y')
'11/2015'
>>> partial_date = PartialDate("2015")
>>> partial_date
2015
>>> partial_date.format('%Y', '%m/%Y', '%m/%d/%Y')
'2015'
Thanks for their collaborations to
lorinkoz
howieweiner
bbirke
Metadata
Release files for r-django-partial-date 1.3.1.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 | Actions |
|---|---|---|---|---|
| r-django-partial-date-1.3.1.1.tar.gz | 5.0 kB | Without provenance | Details for r-django-partial-date-1.3.1.1.tar.gz |
Release files / r-django-partial-date-1.3.1.1.tar.gz
| Download URL | r-django-partial-date-1.3.1.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebc11e4e2827c5d356d0435c51e3255a443ba3445e9d4a6b7b581f252ea5f21d
|
|
BLAKE2b-256 checksum How to use checksums |
338308c048646c4f772db76eb47b34e839e5e731aa3593681b6748925b48162c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for r-django-partial-date 1.3.1.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.