slashmili / django-jalali

Jalali DateField support for Django model

Home Page:http://pypi.python.org/pypi/django_jalali

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with auto_now_add

AminHP opened this issue · comments

It seems there is a problem when auto_now_add is True and TIME_ZONE is Asia/Tehran. Here is an example:

  • Python version: 3.8.6
  • Django version: 3.1.4
  • django_jalali version: 4.1.0
  • jdatetime version: 3.6.2
  • OS: ubuntu 18.04

foo/models.py:

from django.db import models
from django_jalali.db import models as jmodels

class Bar(models.Model):
    objects = jmodels.jManager()
    name =  models.CharField(max_length=200)
    date =  jmodels.jDateField()
    def __str__(self):
        return "%s, %s"%(self.name, self.date)

class BarTime(models.Model):
    objects = jmodels.jManager()
    name =  models.CharField(max_length=200)
    datetime = jmodels.jDateTimeField(auto_now_add=True)
    def __str__(self):
        return "%s, %s" %(self.name, self.datetime)

jalali_test/settings.py

...

TIME_ZONE = 'Asia/Tehran'

...

shell:

python manage.py shell  
Python 3.8.6 (default, Oct  6 2020, 03:22:36) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from foo.models import BarTime
>>> BarTime().save()
>>> BarTime.objects.all()
<QuerySet [<BarTime: , 1399-09-25 23:29:58.793907+0330>]>
>>> dt = BarTime.objects.all()[0].datetime
>>> dt
jdatetime.datetime(1399, 9, 25, 23, 29, 58, 793907, tzinfo=Asia/Tehran)
>>> BarTime.objects.filter(datetime=dt)
<QuerySet []>
>>>

Am I missing something?

Thanks @AminHP for reporting.
I've created a PR(#125) to fix the problem.
Could you please confirm that the patch fixes your problem?
Thanks

Thank you @hramezani for your quick response, the patch solves the problem :)

Thanks for the feedback. I will make a new release with the fix soon.

I just created a new release with the fix.
django-jalali 4.1.1