slashmili / django-jalali

Jalali DateField support for Django model
http://pypi.python.org/pypi/django_jalali
BSD 3-Clause "New" or "Revised" License
254 stars 53 forks source link

Fixture does not work for jdatetime field #92

Closed omides248 closed 5 years ago

omides248 commented 5 years ago

Please provide your configurations and softwares version

Dear all, I have deployed django-jalali in my project. Recently, I was trying to restore a backup which was built using fixture. Unfortunately, when I try to restore backup using fixture loaddata all the dates are saved in Jalali format while django needs Gregorian format. As an example there is no 29th day of February which makes an error.

https://ibb.co/JCft2Lb https://ibb.co/svJDCwt

slashmili commented 5 years ago

Hmm something is wrong here!

The dates are all should have been saved in DB in Gregorian date not Persian date. This is an example of what I have in a sample app:

sqlite> select * from foo_bartime;
1|date in gregorian|2019-07-08 09:49:53+00:00

What I can suggest:

  1. figure out why the dates are saved in Jalali in a sample project
  2. apply the fix in your main project
  3. convert the dates to Gregorian and create a new json
  4. import jsons file.

BTW you didn't provide any detail of versions that you are running so I can't give you much of advise/

omides248 commented 5 years ago

I use of django 2.3 and python3.6 and in setting.py file, i set:

LANGUAGE_CODE = 'fa-ir' TIME_ZONE = 'Asia/Tehran' USE_I18N = True USE_L10N = True USE_TZ = False

DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'db_name', 'USER': 'db_user_name', 'PASSWORD': 'pass', 'HOST': 'localhost', 'PORT': '5432', } }

and part of json when built fixture:

{ "model": "bon.user", "pk": 19, "fields": { "password": "", "last_login": null, "is_superuser": false, "username": "42907", "first_name": "\u0627\u0642\u0627\u06cc", "last_name": "\u0646\u06cc\u06a9\u0646\u0627\u0645", "email": "", "is_staff": false, "is_active": true, "date_joined": "2019-04-29T21:53:35.396", "present_code": "42907", "reagent_user": null, "phone_number": "+98915123618", "verification_code": "", "present_list": "[]", "created_at": "1398-02-09 21:53:35.396628", "order_number": null, "groups": [], "user_permissions": [] } }, { "model": "bon.user", "pk": 20, "fields": { "password": "", "last_login": null, "is_superuser": false, "username": "99043", "first_name": "\u0627\u0645\u06cc\u0631", "last_name": "\u0627\u0628\u0631\u0627\u0647\u06cc\u0645\u06cc", "email": "", "is_staff": false, "is_active": true, "date_joined": "2019-04-29T21:58:03.139", "present_code": "99043", "reagent_user": null, "phone_number": "+9891523123", "verification_code": "", "present_list": "[]", "created_at": "1398-02-09 21:58:03.140036", "order_number": null, "groups": [], "user_permissions": [] } },

created_at field is persian