Is it possible to support partial dates with the DateInput widget? #242
Unanswered
SamuelJennings
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Well, internally I can store a date only as >>> from datetime import date
>>> date(2025, 10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function missing required argument 'day' (pos 3)
>>>>>> date(2025, 10, None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer
>>>I therefore have no idea how to represent a partial date internally. Does Postgres or any other DB backend offer such a type? I have never heard of any. Is there any unofficial Python support for such a type? Having such a module would help me a lot. However, I don't want to be dependent on django-partial-date, that library doesn't seem to be maintained well. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I do a lot of work in digitization and archiving of legacy data/datasets from various research institutions. One problem with such data is that dates are very often not recorded in full. This obviously presents a problem. On one hand, I'd prefer to use a proper date type at the database level to support date-based lookups/queries. On the other hand, I don't want to force users to enter data which is unknown/unclear to them.
At the model level, I solve this by using a
PartialDateFieldfrom thedjango-partial-datepackage which handles conversion from an ISO format string to a proper date type. and back again. Unfortunately, I've never found a nice date widget to support entry of partial dates on the client side.The
DateInputfordjango-formsetlooks super and returns the correct format that I would require. I'm just curious if you think it's possible for date inputs indjango-formsetto optionally validate partial dates? E..g. "2025", "2025-10", "2025-10-22".Beta Was this translation helpful? Give feedback.
All reactions