Interesting solution - after all that maybe it's more concise to just
use the 'extra' filter instead since you're making it specific to
mysql anyway, and you could use mysql date functions.

By the way, in answer to your original question on this thread, there
already is a ticket to add F() + timedelta.

http://code.djangoproject.com/ticket/10154

On Fri, Oct 15, 2010 at 2:48 PM, Marc Aymerich <glicer...@gmail.com> wrote:
>
>
> On Fri, Oct 15, 2010 at 7:54 PM, Alec Shaner <asha...@chumpland.org> wrote:
>>
>> On Fri, Oct 15, 2010 at 1:26 PM, Marc Aymerich <glicer...@gmail.com>
>> wrote:
>> >
>> > Instead of use datatime.timedelta I convert it to string with this
>> > format:
>> >  YYYYMMDDHHMMSS and now all works fine with mysql :) Unfortunately this
>> > part
>> > of code doesn't be database independent :(
>> >
>> > Thank you very much alec!
>> >
>> > --
>> > Marc
>>
>> No problem.
>>
>> So if you don't mind, what does your query filter look like now using
>> the converted format?
>>
>
> hi :)
> this is the get_query_set method of my custom Manager:
> def get_query_set(self):
>     c=config.get('ignore_bill_period')
>     #c is a dict like this {u'hours': u'00', u'seconds': u'00', u'minutes':
> u'00', u'days': u'07'}
>     ignore_period = c['days']+c['hours']+c['minutes']+c['seconds']
>     delta_ignore_period = datetime.timedelta(days=int(c['days']),
>         hours=int(c['hours']), minutes=int(c['minutes']),
> seconds=int(c['seconds']))
>     now_sub_ignore = datetime.datetime.now() - delta_ignore_period
>     #IF db backend is MySQL:
>     return super(pending_of_billManager,
> self).get_query_set().filter(Q(cancel_date__isnull=False, \
>         cancel_date__gt=F('register_date') + ignore_period) |
> Q(cancel_date__isnull=True, \
>         register_date__lt=now_sub_ignore))
>     #ELSE:
>     #return super(pending_of_billManager,
> self).get_query_set().filter(Q(cancel_date__isnull=False, \
>     #    cancel_date__gt=F('register_date') + delta_ignore_period) |
> Q(cancel_date__isnull=True,
>     #    register_date__lt=now_sub_ignore))
> a lot of code for a simple query, but it's the best I can do :)
> br
> --
> Marc
>
> --
> 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.
>

-- 
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.

Reply via email to