slashmili / django-jalali

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

The widget working fine but the date is not jalali! #169

Closed xSerioUsx78 closed 2 years ago

xSerioUsx78 commented 2 years ago

Hi, i added the widget in admin.py and the styling works good, but the date is not jalali! is this the default or i can fix it ?

hramezani commented 2 years ago

Hi, Please provide your model and admin code. it would be great to provide a picture of the rendered widget. Then I will take a look and let you know! Thanks!

xSerioUsx78 commented 2 years ago

First of all, Thank you for the fast response. I summarized the code so that you would not be bothered when checking. my django version: 4.0.2

models.py

    from django_jalali.db import models as jmodels

    class PostManager(jmodels.jManager):
        ...

    class Post(models.Model):
        ...
        timestamp = jmodels.jDateTimeField(
            default=timezone.now, verbose_name=_('تاریخ و زمان انتشار'))
        STATUS = Choices(('D', 'پیش نویس'), ('P', 'منتشر شده'))
        status = StatusField(choices_name='STATUS', default='D',
                             verbose_name=_('وضعیت انتشار'))
        objects = PostManager()

admin.py

    from django.contrib import admin
    from django.utils.html import format_html
    from hitcount.models import HitCount
    from .models import Post
    import django_jalali.admin as jadmin

    # Register your models here.

    @admin.register(Post)
    class PostAdmin(admin.ModelAdmin):
        ...

widget

hramezani commented 2 years ago

Thanks for providing more info. I will check it later and will let you know!

xSerioUsx78 commented 2 years ago

Thank you!

slashmili commented 2 years ago

@xSerioUsx78 just a side note: please drop the screenshots into the comment textbox GitHub allows us to share/upload the images safely inside GitHub platform.

hramezani commented 2 years ago

@xSerioUsx78 I've created a fresh project and the widget works well for me

pic

Which version of Django and djnago-jalali are you using?

xSerioUsx78 commented 2 years ago

@slashmili Sorry for that, i will share via github next time thank you.

@hramezani Django 4.0.2, django-jalali 5.1.0

I found out where the problem came from.

the problem was from default=timezone.now

timestamp = jmodels.jDateTimeField(
        default=timezone.now, verbose_name=_('تاریخ و زمان انتشار'))

I changed it to default=jdatetime.datetime.now

timestamp = jmodels.jDateTimeField(
        default=jdatetime.datetime.now, verbose_name=_('تاریخ و زمان انتشار')) 

and its work perfectly now. thank you for the great project, keep it up.

hramezani commented 2 years ago

Perfect! Thanks for letting us know! I close this issue.

xSerioUsx78 commented 2 years ago

Now the widget works but when i tried to add a post, django give me an error and it's weird, when i made the jdatetime field auto_now_add=True it works, but when i tried to add datetime manually it give me this error

1400-11-19 18:41:59در محدوده زمانی Asia/Tehran، قابل تفسیر نیست؛ ممکن است نامشخص باشد یا اصلاً وجود نداشته باشد.

Then i changed the timezone to utc in settings.py but steel i got this error.

1400-11-19 18:41:59در محدوده زمانی utc، قابل تفسیر نیست؛ ممکن است نامشخص باشد یا اصلاً وجود نداشته باشد.

hramezani commented 2 years ago

I would suggest creating a new issue for this issue because this one is closed. please also mention more information about the Django and Django-jalali versions and your settings.