Dropdown sorting in django-admin
Posted
by Andrey
on Stack Overflow
See other posts from Stack Overflow
or by Andrey
Published on 2009-07-20T06:07:41Z
Indexed on
2010/03/28
7:03 UTC
Read the original article
Hit count: 298
I'd like to know how can I sort values in the Django admin dropdowns. For example, I have a model called Article with a foreign key pointing to the Users model, smth like:
class Article(models.Model):
title = models.CharField(_('Title'), max_length=200)
slug = models.SlugField(_('Slug'), unique_for_date='publish')
author = models.ForeignKey(User)
body = models.TextField(_('Body'))
status = models.IntegerField(_('Status'))
categories = models.ManyToManyField(Category, blank=True)
publish = models.DateTimeField(_('Publish date'))
I edit this model in django admin:
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'publish', 'status')
list_filter = ('publish', 'categories', 'status')
search_fields = ('title', 'body')
prepopulated_fields = {'slug': ('title',)}
admin.site.register(Article, ArticleAdmin)
and of course it makes the nice user select dropdown for me, but it's not sorted and it takes a lot of time to find a user by username.
© Stack Overflow or respective owner