Django admin: Change selected box of related fields to autocomplete

前端 未结 5 1433
有刺的猬
有刺的猬 2020-12-04 16:55

We have some models that are have a user as a foreign key. But with about 25000 users in our system, it\'s a bit daunting to find the one we need.

Is there a solutio

5条回答
  •  难免孤独
    2020-12-04 17:49

    Django 2.0 admin has autocomplete built in, just set the autocomplete_fields field on the ModelAdmin class. e.g.

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

提交回复
热议问题