Home > Back-end >  save Jalali(Hijri shamsi) datetime in database in django
save Jalali(Hijri shamsi) datetime in database in django

Time:05-23

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?

CodePudding user response:

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).

  • Related