Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle select boxes in django admin with large amount of records

my app has grown so that that drop downs in the django admin have 100,000s of options. I can't even open my admin anymore because of its load on the database, not too mention I wouldn't be able to find an option in the select box.

Does django have an autocomplete option?

What is the best option for handling big data in django admin?

like image 417
Atma Avatar asked Nov 02 '17 19:11

Atma


1 Answers

Django 2.0 has introduced a new feature on the admin site, called autocomplete_fields, which is helpful for models with foreign keys. It replaces the normal <select> element with an autocomplete element:

 class QuestionAdmin(admin.ModelAdmin):
     ordering = ['date_created']
     search_fields = ['question_text']

 class ChoiceAdmin(admin.ModelAdmin):
     autocomplete_fields = ['question']

Here's a screenshot of the element:

Screenshot

like image 96
Flimm Avatar answered Oct 03 '22 22:10

Flimm