Skip to content

Commit

Permalink
fix: Fix "'NoneType' object has no attribute 'widget'" when M2M uses …
Browse files Browse the repository at this point in the history
…intermediary model (#10)
  • Loading branch information
HenrichHanusovsky authored Sep 13, 2022
1 parent df42f58 commit 61ea6f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/unfold/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def formfield_for_manytomany(self, db_field, request, **kwargs):

form_field = super().formfield_for_manytomany(db_field, request, **kwargs)

# If M2M uses intermediary model, form_field will be None
if not form_field:
return None

if isinstance(form_field.widget, SelectMultiple):
form_field.widget.attrs["class"] = " ".join(SELECT_CLASSES)

Expand Down

0 comments on commit 61ea6f7

Please sign in to comment.