Monday, October 29, 2018

Many to Many field in ModelForm - with tens of thousands of records


We are using django 1.11 for our ecommerce site. 

We are facing an issue with modelform and many to many field in it as follows:

Lets say there are two models:

class A(models.Model):
       c = models.CharField()

class B(models.Model):
      a = models.ManyToManyField('A')

Now if I define a modelform:

class MF(models.ModelForm):
      class Meta:
              model = B
              fields = [a,]

We are using django widget tweaks to render the fields in MF. Now if there are tens of thousands of records in A, the MF form rendering causes the page to hang as the widget will try to show the whole set of tens of thousands of records option for field a. 

Hence, would appreciate if anyone could suggest a smart solution wherein the above issue is taken care of. 


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment