List Info

Thread: Datetime ordering correct?




Datetime ordering correct?
user name
2007-12-26 16:04:59
I have a simple functions that pulls objects from the
database that
are between a date range:

def get_sp_from_date_range(start_date, end_date,
order=False):
    s_products =
ScheduledProduct.objects.filter(start__gt=start_date)
    s_products = s_products.filter(finish__lt=end_date)
    if order:
        return s_products.order_by('finish')
    else:
        return s_products

When order==True these are the results:

..
2007-12-25 00:00:00
2008-01-01 00:00:00
2007-12-25 01:27:11
2007-12-25 04:27:11
2007-12-25 08:27:11
...

Is this the correct behavior?

Thanks,
Ryan Kaskel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Datetime ordering correct?
user name
2007-12-26 17:24:55
On Dec 26, 2007 4:04 PM, Ryan K <ryankaskelgmail.com> wrote:
> def get_sp_from_date_range(start_date, end_date,
order=False):
>     s_products =
ScheduledProduct.objects.filter(start__gt=start_date)
>     s_products =
s_products.filter(finish__lt=end_date)
>     if order:
>         return s_products.order_by('finish')
>     else:
>         return s_products
>
> When order==True these are the results:
>
> ..
> 2007-12-25 00:00:00
> 2008-01-01 00:00:00
> 2007-12-25 01:27:11
> 2007-12-25 04:27:11
> 2007-12-25 08:27:11
> ...
>
> Is this the correct behavior?

It doesn't look like it.  

with settings.DEBUG = True, you can inspect the SQL that's
being run this way:
>>> from django.db import connection
>>> print connection.queries

If the SQL being run includes the expected order by clause,
then it's
time to go to the DB to verify that it gives the expected
results.

Not that the SQL included in connection.queries is a bit
different
from what's actually run on your DB since quoting is handled
by the DB
driver, not Django, but it should get you in the right
ballpark.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )