Ok, I added 'from datetime import datetime' to my views.py and tried the following code in one of my functions: 'assert False, datetime.timedelta(days=20)'
but i get the following error: AttributeError at /plush/newarrivals/ type object 'datetime.datetime' has no attribute 'timedelta' /////////// Thanks for any help On Oct 11, 10:56 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > On 10/11/07, Greg <[EMAIL PROTECTED]> wrote: > > > I have a model called Style that contains a DateField. It stores the > > date when the record was created. I want my template to only show > > Style records that were created less than 20 days ago. I think that > > this needs to be done within the view, but not sure if there is a > > filter that I can use in the template. Here is my model: > > You want to use Python's 'timedelta' class to calculate a date 20 days > in the past: > > http://docs.python.org/lib/datetime-timedelta.html > > And then use the 'gt' field lookup, combined with the calculated "20 > days ago" date, to do the query: > > http://www.djangoproject.com/documentation/db-api/#gt > > So something like this: > > import datetime > > def newarrivals(request): > cutoff_date = datetime.date.today() - datetime.timedelta(days=20) > s = Style.objects.filter(newstyles__gt=cutoff_date) > ...etc... > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---