On Thu, 2009-03-05 at 14:54 -0800, John M wrote: > I'm having a strange problem with running django on a Cherrypy > server. > > in my views.py, I setup a variable called oneweekago, and set it to > today() - (days=7) (it's obviously a date type variable), then in my > query, I ask for all records that are __LTE=oneweekago. > > This code works perfect the day I start my server, but the next day, > if there are records that meet the criteria, it doesn't. Like the > variable oneweekago is not getting recalculated. If I restart the > server, it works great. > > Here's the actual code in question: > > oneweekago = datetime.date.today() - datetime.timedelta(days=7)
If all this indentation is correct (and the email has screwed things up pretty badly here, so you might want to use dpaste next time -- and switch to spaces instead of tabs for your Python code, which is pretty normal), then this line is going to be a problem. It's evaluated once, when the file is imported. If the file isn't imported again (which would happen if the server didn't restart), the value won't change just because the date did. You'd be better off doing that computation each time you need it (once per function). It's hardly a huge timesink to do the computation. Regards, 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-users@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 -~----------~----~----~----~------~----~------~--~---