Malcolm Tredinnick escribió:

> 
> On Thu, 2007-03-15 at 21:53 +0100, Matias Surdi wrote:
>> Hi,
>> 
>> I'm my urls.py I have the following queryset for a generic view:
>> 
>> published_posts_dict = {'queryset':
>>
Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}
>> 
>> the problem is, with the filter pub_date__lte=datetime.now() .
> 
> The datetime.now() is evaluated exactly once -- when this dictionary is
> created. That is at import time. So, not surprisingly, as real world
> time moves forwards, the date you are comparing against remains in the
> past.
> 
> A couple of alternatives are:
> 
> (1) Wrap the generic view in another function to compute the real
> queryset (see
>
http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/
> )
> 
> (2) Have a look in django/db/models/__init__.py at the LazyDate class.
> It is well documented in the docstrings, so it should be easy to work
> out how to use it. Replacing datetime.now() with LazyDate() should work,
> I suspect.
> 
> Regards,
> Malcolm
> 
> 
> 
> 


Thanks a lot!



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

Reply via email to