I am using Python 3.5, Django 2.0 and Django REST Framework 3.7.7 I added django-jalali 3.0.2 to my apps for jalali calelndar compatibility. This app works fine when using admin or shell, but when I send requests using DRF, datetime object is validated using the Gregorian calendar. As a result I cannot use date with a string like 1397-02-31 or 1397-02-30. This is the response I get:
HTTP 400 Bad Request Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept
{
"schedule_time": [
"Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format."
]
}
THis error originates from line 252 of django_jalali/db/models.py
try: # Seconds are optional, so try converting seconds first.
t = time.strptime(datetime_obj, '%Y-%m-%d %H:%M:%S')
because srtptime presumes datetime_obj
is Datetime object not jDatetime. As mentioned before this is not a problem in admin or shell. I also have tested setting locale to 'fa_IR'
and changing the object manager but no luck so far. Is there a clean solution for this or do I have to write my own app?
P.S. I've noticed date_hierarchy
in admin only uses Datetime (not jDatetime). I tried changing it but it fails django checks. how can I change this to jalali?
I've also posted this as an issue on django-jalali github page and still waiting for an answer.