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

jDateField() can not get jalali date #190

Closed mshzsh closed 2 years ago

mshzsh commented 2 years ago

I send 1371-12-07 to jDateField but it save 750-09-16

hramezani commented 2 years ago

Could you please provide more information? Django and django-jalali version? Please provide an example code or test to make it easy to understand

mshzsh commented 2 years ago

Django : 4.0.6 django-jalali : 6.0.0 djangorestframework : 3.13.1

class User(models.Model):
    birthdate = jmodels.jDateField(null=True)
class UserDetailsSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['birthday']

curl --location --request PATCH 'http://127.0.0.1:4801/user-details/' --form 'birthdate="1371-12-07"'

Response : {"birthdate": "750-09-16"}

hramezani commented 2 years ago

Based on the doc, You need to define your field in serializer as well. So:

from django_jalali.serializers.serializerfield import JDateField

class UserDetailsSerializer(serializers.ModelSerializer):
    birthdate = JDateField()

    class Meta:
        model = User
        fields = ['birthday']
hramezani commented 2 years ago

@mshzsh if it's fixed your problem. Please close the issue