Re: extend queryset field lookups for time

2010-01-26 Thread Malcolm Box
On Tue, Jan 26, 2010 at 9:14 AM, Henrik Genssen  wrote:

> how would I extend the field lookup to get somethnng like this:
>
> SELECT ... WHERE EXTRACT('hour' FROM pub_date) > 20
> what is for MYSQL:
> SELECT ... WHERE HOUR(pub_date) > 20
> to get all entries where the timepart of pub_date is grater then 8pm
>
>
Have a look at the extra() method on the queryset -
http://docs.djangoproject.com/en/1.1/ref/models/querysets/#queryset-api

With that you can inject the relevant SQL to extract a part of a datetime
field and filter by < > = etc.

Alternatively, store your table with the datetime split into year, month,
day, hour, minute etc fields.  You could add processing to the model's
save() function to do this transparently.

 As far as I know there's no built-in way to do what you want.

Cheers,

Malcolm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



extend queryset field lookups for time

2010-01-26 Thread Henrik Genssen
Hi,

how would I extend the field lookup to get somethnng like this:

SELECT ... WHERE EXTRACT('hour' FROM pub_date) > 20
what is for MYSQL:
SELECT ... WHERE HOUR(pub_date) > 20
to get all entries where the timepart of pub_date is grater then 8pm


and how would I change the existing of YEAR, MONTH, DAY for > and <...

regards

-- Hinnack

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: extend queryset field lookups for time

2009-12-18 Thread hinnack
has nobody an idea for this?
Hour and Minute itself seems to be easy - should just be added to
where.py
WhereNode class => make_atom() - but how to extend the functionality
to greater / lower?


-- Hinnack

On Nov 27, 2:53 pm, Hinnack  wrote:
> Hi,
>
> how would I extend the field lookup to get somethnng like this:
>
> SELECT ... WHERE EXTRACT('hour' FROM pub_date) > 20
> what is for MYSQL:
> SELECT ... WHERE HOUR(pub_date) > 20
> to get all entries where the timepart of pub_date is grater then 8pm
>
> and how would I change the existing of YEAR, MONTH, DAY for > and <...
>
> regards
>
> -- Hinnack

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




extend queryset field lookups for time

2009-11-27 Thread Hinnack
Hi,

how would I extend the field lookup to get somethnng like this:

SELECT ... WHERE EXTRACT('hour' FROM pub_date) > 20
what is for MYSQL:
SELECT ... WHERE HOUR(pub_date) > 20
to get all entries where the timepart of pub_date is grater then 8pm


and how would I change the existing of YEAR, MONTH, DAY for > and <...

regards

-- Hinnack

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.