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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/ceb85a59-b595-401f-906b-275f33265d92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to