Closed PouriaN closed 4 years ago
Not sure, it works for me:
python manage.py shell
Python 2.7.12 (default, Oct 31 2016, 10:59:21)
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.10.5'
>>> from foo.models import Bar
>>> import jdatetime
>>> from foo.models import BarTime
>>> BarTime(name="Bar Time now", datetime=jdatetime.datetime(1390,8,2,12,12,12)).save()
>>> BarTime.objects.filter(datetime__year="1390")
<QuerySet [<BarTime: Bar Time now, 1390-08-02 12:12:12+0000>]>
Which version of python and Django are you using?
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.get_version()
'1.10.4'
I got this error on Django 1.10.3 and Python 2.7.9 FieldError: Unsupported lookup 'year' for jDateTimeField or join on the field not permitted.
Hmmm, I added a test b75dab319460bbe37b6c56299eb9dfdc1332ec5e and it passed.
What's different between what you and I do?
I have a same problem in Django 1.11.4 and Python 3.6.1 for get_object_or_404:
_publishtime is jDateTimeField
post = get_object_or_404(Post, publish_time__year=1396)
error:
Unsupported lookup 'year' for jDateTimeField or join on the field not permitted.
Also there is a similar problem in 'unique_for_date' option in fields. For example for a slug:
slug = models.SlugField(max_length=250, unique_for_date='publish_time')
You'll see a same error for 'day':
Unsupported lookup 'day' for jDateTimeField or join on the field not permitted.
@metemaddar since you can reproduce it, do you have any solution for it?
I should read it and work on it. I can not answer for about a week. I have no internet access for a while. But I like to work on it intensively. Thanks a lot @slashmili
@slashmili I think it's better to jDateTimeField and jDateField should inherit from DateTimeField and DateField. All lookups related to date/time fields only work in subclasses of these fields, look at this line: https://github.com/django/django/blob/master/django/db/models/functions/datetime.py#L66
I'm closing this issue. Feel free to open it again if you have further questions.
Hi dudes, I created this field in my model
createTimeJalali = jmodels.jDateTimeField(auto_now=True)
and I want to get a query based on year in my viewnews_list = News.objects.filter(createTimeJalali__year=y).order_by('-id')
but I get this error when I run the projectUnsupported lookup 'year' for jDateTimeField or join on the field not permitted. what's the problem here?