Django form with ManyToMany field with 500,000 objects times out

前端 未结 4 2199
走了就别回头了
走了就别回头了 2021-02-13 05:03

Lets say for example I have a Model called \"Client\" and a model called \"PhoneNumbers\"

class PhoneNumbers(models.Model):
    number = forms.IntegerField()

cl         


        
4条回答
  •  梦谈多话
    2021-02-13 05:58

    Since Django 2.0, Django Admin ships with an autocomplete_fields attribute that generates autocomplete widgets for foreign keys and many-to-many fields.

    class PhoneNumbersAdmin(admin.ModelAdmin):
        search_fields = ['number']
    
    class ClientAdmin(admin.ModelAdmin):
        autocomplete_fields = ['number']
    

    Note that this only works in the scope of Django admin of course. To get autocomplete fields outside the admin you would need an extra package such as django-autocomplete-light as already suggested in other answers.

提交回复
热议问题