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

utcoffset(dt) argument must be a datetime instance or None, not datetime #101

Closed aminbahrabadi closed 4 years ago

aminbahrabadi commented 5 years ago

Recently when I create a jDateTimeField, this error appears:

TypeError at /..../..../profile/2/change/

utcoffset(dt) argument must be a datetime instance or None, not datetime

The error seems to be here:

C:\Users...\Envs...\lib\site-packages\django_jalali\forms__init__.py in prepare_value

            value = to_current_timezone(value)
slashmili commented 5 years ago

@aminbahrabadi please update jdatetime package in your dependencies list

it's fixed in https://github.com/slashmili/python-jalali/pull/62

aminbahrabadi commented 5 years ago

I still get that error and about jdatetime: Requirement already up-to-date: jdatetime in c:\users\**\envs\**\lib\site-packages (3.6.2)

smb-h commented 4 years ago

I still get this error :(

aminbahrabadi commented 4 years ago

@smb-h me too!

hramezani commented 4 years ago

@aminbahrabadi , @smb-h Thanks for reporting again :). Is it possible for you guys to post your environment information like OS, Python version, Django version, django_jalali version, python-jalali version, and ...

Also, It would be good to create a minimal project with the bug. it would help us to find the problem easier.

Thanks

smb-h commented 4 years ago

@hramezani of course. OS Ubuntu 2020.04 lts Python 3.8.2 Django 3.0.2 django-jalali 3.3.0

and the field causing this problem date_joined = jmodels.jDateTimeField(auto_now_add = True, auto_now = False, verbose_name = _('Created')) Thank you!

Rebix commented 4 years ago

I'm still getting the error

django-jalali==3.3.0 jdatetime==3.6.2

legitYosal commented 4 years ago

I still have this problem: Django 3.0.7
django-jalali 3.4.0
jdatetime 3.6.2
I have this field in my model: timeStamp = jmodels.jDateTimeField(default=jdatetime.datetime.now, editable=False) and because timeStamp tzinfo is not set automatically I have to set it in save method manually:

    def save(self, *args, **kwargs):
        if not is_aware(self.timeStamp):
            self.timeStamp = make_aware(self.timeStamp)
        super(Post, self).save(*args, **kwargs)

this works perfectly and doesn't bother but when I'm updating my model it gives:

TypeError: utcoffset(dt) argument must be a datetime instance or None, not datetime

steps to create:

instance = Model.objects.get(id=?)
instance.save() ==> makes error
hramezani commented 4 years ago

Hi @usefss, Thanks for reporting the problem. The https://github.com/slashmili/django-jalali/pull/108 fixes this problem. we need time to check the PR and merge it. Then we will prepare a release for it.

hramezani commented 4 years ago

django-jalali 4.0.0 is out https://pypi.org/project/django-jalali/4.0.0/ Thanks @slashmili :+1:

slashmili commented 4 years ago

Thanks for your great work @hramezani 👏

I'm closing this ticket for now, feel free to open it if you still have the same issue