Use __gte lookup: latest_articles_list = Article.objects.filter(pub_date__gte=thirty_days_ago)
and take a look at other lookups: https://docs.djangoproject.com/en/1.6/ref/models/querysets/#field-lookups Cheers, Tom Dne Sun, 20 Jul 2014 20:50:53 -0700 (PDT) Conner DiPaolo <[email protected]> napsal(a): > I've been thinking about it and I think this should work but it doesn't. > > latest_articles_list = Article.objects.filter(pub_date>=thirty_days_ago) > > Django is saying 'pub_date' is not defined, even though I used it to filter > a different list and it worked fine. What is wrong?? > Thanks > > > On Sunday, July 20, 2014 8:16:21 PM UTC-7, Conner DiPaolo wrote: > > > > Hi! > > I was wondering if anybody knew how to create a list based on that list > > having a DateTime attribute that is less than 30 days old. I already have a > > boolean in the model itself of 'published_recent_month' that can say if it > > is or is not published within a month, but how do I put into that a list to > > put into a template? I know how to do a list based on pub_date and have it > > be a certain length, but I would rather have the list be dynamic to usage. > > > > Thanks a lot! > > > > > > abbreviated model to show the boolean definition I have: > > class Model(models.Model): > > ... > > def published_recent_month(self): > > return self.pub_date >= timezone.localtime(timezone.now()) - > > datetime.timedelta(days=30) > > > > abbreviated view using what I already know: > > def index(request): > > ... > > latest_25_list =Model.objects.order_by('-pub_date')[:25] > > > > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20140721073041.3789df05%40bodhi. For more options, visit https://groups.google.com/d/optout.

