On 8/15/06, keukaman <[EMAIL PROTECTED]> wrote:
>
> I'm using generic views to display some blog entries. It's a very
> simple app that i'm using to learn django.
>
> The problem I'm having is trying to sort the output with the newest
> entry showing at the top. Does anyone have a simple model.py and
> template.html I could look at that shows this? Thank you.
>

This model will sort by date, newest first:

class Post(models.Model):
    title = models.CharField(maxlength=200)
    slug = models.SlugField(prepopulate_from=('title',))
    pub_date = models.DateTimeField('date published', auto_now_add=True)
    body = models.TextField()


    class Meta:
        ordering = ('-pub_date',)


Then all you have to do is use a generic view like you might normally
do, with Post.objects.all() in the dict. The order of them in the
template will be what you want.

Jay P.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to