save Jalali(Hijri shamsi) datetime in database in django

381 Views Asked by At

I have a Django project, and I want to save created_at datetime in the database. I generate datetime.now with jdatetime (or Khayyam) python package and try to save this in DateTimeField. But sometimes it raises error because the Gregorian(miladi) date of the entry does not exist. what can I do about this?

1

There are 1 best solutions below

0
On BEST ANSWER

In my idea, you can save two model fields. One is DateTimeField contains gregorian datetime, and another one, CharField contains converted Jalali to a String value and save it. The DateTimeField for functionality, e.g., filter between to datetime. The StringField for representing in response(without overload).