0

Is it possible to add/use a widget to/for an extension?

def group(cls, admin_cls):

    cls.add_to_class('group',
        models.ManyToManyField(
            Group,
            widget=?????
          ))

I want to use Django's FilteredSelectMultiple for the many to many field.

Paolo
  • 20,112
  • 21
  • 72
  • 113
nelsonvarela
  • 2,310
  • 7
  • 27
  • 43

1 Answers1

0

What exactly are you filtering for? If it's a static value, you can simply use the limit_choices_to attribute to the ManyToManyField. E.g.

cls.add_to_class('group',
    models.ManyToManyField(
         Group,
         limit_choices_to={'name': 'Editors'},
    ))

If it's a dynamic value, you'd have to override the formfield_for_dbfield function of the admin class to return the field you like. Let me know if you need an example for that casse.

Jonas
  • 970
  • 1
  • 8
  • 17