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

10👍

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.

30👍

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

12👍

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']
👤Flimm

0👍

Another option is to add readonly_fields instead of raw_id_fields

👤Kritz

Leave a comment