Django model timerange filtering method -


I saw the next two methods in an old question but it is not clear to me that what is the difference between:

  {'date_time_field__range': (datetime.datetime.combine (date, datetime.time.min), datetime.datetime.combine (date, datetime.time.max))}  < / Ex> 

and

  YourModel.objects.filter (datetime_published__year = '2008', datetime_published__month = '03 ', datetime_published__day =' 27 ')  
< / Div>

It was confused about myself, but I think I have done this: -DI is very much used I found.

When you do:

  YourModel.objects.filter (datetime_published__year = '2008', datetime_published__month = '03 ', datetime_published__day =' 27 ')  

The SQL will look like this:

  SELECT ... Where extract ('year' from Pub_date) = '2008' and extract ('pub_date' from 'month') = '03' and extract ('day' to pub_date) = '27';  

While this part of the generic date-based visuals of Django:

  {date_time_field_range}: (datetime.datetime.combine (date, datetime.time. Min), Datetime.datetime.combine (date, datetime.time.max))}  

Something happens:

  yourModel.objects. Filter (datetime_published__range = (Datetime.datetime.combine ('2008-03-27', datetime.time.min), datetime.datetime.combine ('2008-03-27', datetime.time.max))  

which generates SQL with lines:

  SELECT ... WHERE between datetime_published '2008-03-27 00:00:00' and ' 2008-03-27 23: 59: 59 ';  

(Timestom in last SQL example The form format is clearly wrong, but you get this idea)

Hope you answer your question :)


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -