views:

605

answers:

1

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.

A: 

This is a duplicate see the answer here

googletorp