[Answer]-Django default queryset and widget for ModelForm custom field

1đź‘Ť

âś…

Delete the def __init__ method and code. By putting “pass” inside there, you’re overriding the default functionality of ModelMultipleChoiceField, which your class inherits from, that would utilize the queryset.

Edit:

Re-structure your __init__ method like so:

  def __init__(self, *args, **kwargs):
      if not 'queryset' in kwargs:
          kwargs['queryset'] = Site.objects.all()
      return super(SiteSelectorField, self).__init__(*args, **kwargs)
👤Joseph

Leave a comment