python - Django error in filtering datetime field by date : Join on field X not permitted -
I get another post that shows the time period using the __ date
Can be filtered. However, when I tried on my machine, he never worked.
This is my models.py
class records (models.Model): time = model.DatetimeField (null = true, empty = Trouser) User table content = User = Forecairn for model Serifield (max_language = 36, tap = true, empty = true, exclusive = true)
in the python manage.py.runserver
& gt; & Gt; & Gt; That time import from datetime & gt; & Gt; & Gt; Record from Appname.models & gt; & Gt; & Gt; U = User.objects.filter (user name = 'user') & gt; & Gt; & Gt; R = record.obages.filter (time__data = datetime.today (). Date ()) traceback (most recent call final): file "console" gt; line 1, & lt; Module & gt; File "C: \ Python27 \ lib \ site-packages \ django \ db \ Model \ manager.py", line 163, filter returns in self.get_queryset (). Filter (* Args, ** kwargs) file "C: \ Python27 \ lib \ site-packages \ django \ db \ Model \ query.py", line 590, filter returns in self._filter_or_exclude (False, * args, ** Kwargs) file "C: \ Python27 \ lib \ site-packages \ Django \ db \ Model \ query.py", line 608, _filter_or_exclude clone.query.add_q (in Q (* args, ** kwargs)) "C : \ Python27 \ lib \ site-packages \ django \ db \ Model \ sql \ query.py ", line 1198, add_q section = self._add_q (where_part, used_aliases) file" C: \ Python27 \ lib \ site-packages \ Django \ db \ Model \ sql \ query.py ", file" C: \ Python27 \ lib \ site-packages \ django \ db \ Model \ sql \ query.py ", line 1100, allow_explicit_fk = True in build_filter "C: \ Python27 \ Lib \ site-packages \ django \ db \ m File "C: \ Python27 \ lib \ site-package s \ django \ db \ Model \ sql \ query.py", line \ sql \ query.py ", line 1357, setup_joins names, opts, allow_many, allow_explicit_fk) 1320, names_to_path "lookup type?"% (Name, name [pin + 1]) field error: join in the field 'time in' is not allowed. Did you tell 'date' incorrectly for lookup type?
I'm running Windows 7 Dragon 2.7, django 1.6
Any help is greatly appreciated!
Use __contains instead of __date:
r = record . Afs. Filters (time__contains = datetime.today (). Date ()) Since that __starSwidth (such as 'Value'%) is faster than __class (like '% value%'), therefore < Strong> UPDATE
The best option is:
r = record.object Filler (time-darts with = datetime.today (). Date ())
Comments
Post a Comment