[Fixed]-Improving Performance of Django ForeignKey Fields in Admin


You can use one of the few autocomplete apps for Django. Check them at Django Packages.

There’s also django-extensions that have ForeignKeyAutocompleteAdmin that fit your needs pretty well.


Add raw_id_fields to your model to only show the ID instead of a dropdown.


You’re right, Cerin, the cause of the slowdown is because Django is populating the <select> element with too many options. You might want to use an autocomplete element instead.

Interestingly, Django 2.0 has introduced a new feature on the admin site, called autocomplete_fields, which I think you will find useful in this case. It uses AJAX.

class ExampleAdmin(models.ModelAdmin):
    autocomplete_fields = ['example_field_user']


Another option is to add readonly_fields instead of raw_id_fields


Leave a comment