1

I have the following models:

class Student(models.Model):
    class Meta:
        app_label = 'ground'

    name = models.CharField(max_length=255)

    def __unicode__(self):
        return unicode(self.name)


class Program(models.Model):
    class Meta:
        app_label = 'ground'

    name = models.CharField(max_length=255)
    student = models.ManyToManyField(Student)

    def __unicode__(self):
        return unicode(self.name)

And the following admin:

class ProgramAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.ManyToManyField: {
            'widget': admin.widgets.FilteredSelectMultiple(
                Student._meta.verbose_name_plural, False)
        }
    }

admin.site.register(Program, ProgramAdmin)

As you can see I use django's FilteredSelectMultiple to display a nice select field for the Program admin where I can select multiple students at once.

Problem I have over 2500 students in the database. The browser has problems with rendering all students into the select field. Is there a way to overcome this problem. Like doing stuff with javascript

nelsonvarela
  • 2,310
  • 7
  • 27
  • 43

2 Answers2

1

It's not a browser problem. Django is fetching a list of data of all the students on every single load. If you keep it that way, it will be slow and slower. You can check out raw_id_fields.

Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96
0

I'm currently writing my own autocomplete widget... Stay tuned!

nelsonvarela
  • 2,310
  • 7
  • 27
  • 43