ModelAdmin sorting? ModelAdmin sorting? django django

ModelAdmin sorting?


formfield_for_manytomany

class SongInline(admin.TabularInline):    model = Song    extra = 0    def formfield_for_manytomany(self, db_field, request, **kwargs):            if db_field.name == "soloists":                kwargs["queryset"] = Singer.objects.order_by('last_name')            return super(SongInline, self).formfield_for_manytomany(db_field, request, **kwargs)

That answers your specific question of "ModelAdmin Ordering" but in your case, you can simply define a default ordering for your m2m model via the model ordering model meta class option.

http://docs.djangoproject.com/en/dev/ref/models/options/#ordering

class Singer(models.Model):    # my model    class Meta:        ordering = ['name'] # your select box will respect this as well.