Skip to main content

Provides a Django model and form fields for dates that do not include days.

Project description

Provides a Django model and form fields for dates that do not include days.

Prerequisites

  • Django 3.0+

  • Python 3.6+

Installation

pip install django-daylessdate

Usage

The package provide fields DaylessDateField.

Add djangodaylessdate to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'djangodaylessdate',
    ...
)

DaylessDateField

DaylessDateField stores a date without a day: January 2021, for example.

Its default widget consists of one dropdowns and one input, one for a month and one for the year.

Here’s an example models.py that declares a model with a required dayless date:

from django.db import models
from djangodaylessdate.models import DaylessDateField

class MyModel(models.Model):
    month = DaylessDateField()

The values of DaylessDateField on the model instances can be accessed like so:

>>> a = MyModel.objects.get(id=1)
>>> a
<MyModel: August 2021>
>>> a.month.month
8
>>> a.month.year
2021
>>> print a.month
August 2021

They can also be compared or sorted as would be expected, for example:

>>> m = MyModel.objects.all()
>>> m
[<MyModel: August 2021>, <MyModel: January 2021>]
>>> m[0].month > m[1].month
True
>>> m.order_by('month')
[<MyModel: January 2021>, <MyModel: August 2021>]

In admin.py:

from djangodaylessdate.filters import DaylessDateFilter

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    list_filter = [('month', DaylessDateFilter)]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-daylessdate-1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_daylessdate-1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file django-daylessdate-1.1.tar.gz.

File metadata

  • Download URL: django-daylessdate-1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.2

File hashes

Hashes for django-daylessdate-1.1.tar.gz
Algorithm Hash digest
SHA256 94dad24adacd3b69f2fed258f6983e52f90c679a8bb494b1b69e4e04c6f7a0b1
MD5 ac9f637ddec2e6b9ccedb5b94e4f1bb3
BLAKE2b-256 86d6a5f0b17a07eba0989b467c40dbf1d7c0bc550bc537c790a87514ac230350

See more details on using hashes here.

File details

Details for the file django_daylessdate-1.1-py3-none-any.whl.

File metadata

  • Download URL: django_daylessdate-1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.2

File hashes

Hashes for django_daylessdate-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f9e676cca19f584fb6f77c8cdf6860f808cb6b94b4ff51e52efbf78f792b76c
MD5 1aed02e14bbdc2a34d551514248e55bc
BLAKE2b-256 fcc5621174b902a9e4636228e9c29a63be7427fd2e8166667c49873ad6651d26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page