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


lets example have model called "client" , model called "phonenumbers"

class phonenumbers(models.model):     number = forms.integerfield()  class client(models.model):     number = forms.manytomanyfield(phonenumbers) 

client has manytomany relationship phonenumbers. phonenumbers has 500,000 records in when comes editing client record model form multiselect widget comes m2m filed, takes forever load. in fact, never does. sits there trying load of phone objects assuming.

my workaround tedious things ajax , jquery edit phone numbers in client record. before wasting time of wanted see if there somehow way go without having page hang.

you need create custom widget field lets autocomplete correct record. if don't want roll own: http://django-autocomplete-light.readthedocs.io/

i've used generic relationship support, m2m autocomplete looks pretty easy , intuitive well. see video of use here: http://www.youtube.com/watch?v=fjihiqwkuxi&feature=youtu.be

after reading comment needing outside admin, took @ django-autocomplete-light library. it provides widgets can use outside admin.

from dal import autocomplete django import forms  class personform(forms.modelform):     class meta:         widgets = {             'myformfield': autocomplete.modelselect2(                 # ...             ),         } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -