@@ -676,7 +676,7 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
676676 # we try to pass in. Very annoying because we have to
677677 # un-encapsulate some of this initialization logic, this makes our
678678 # EnumChoiceField pretty ugly!
679- from django_enum .forms import EnumChoiceField , NonStrictSelect
679+ from django_enum .forms import ChoiceFieldMixin , EnumChoiceField , NonStrictSelect
680680
681681 if not self .strict :
682682 kwargs .setdefault ("widget" , NonStrictSelect )
@@ -687,10 +687,12 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
687687 ** kwargs ,
688688 )
689689
690- # we can't pass these in kwargs because formfield() strips them out
691- form_field .enum = self .enum
692- form_field .strict = self .strict
693- form_field .primitive = self .primitive
690+ if isinstance (form_field , ChoiceFieldMixin ):
691+ # we can't pass these in kwargs because formfield() strips them out
692+ form_field .enum = self .enum
693+ form_field .strict = self .strict
694+ form_field .primitive = self .primitive
695+ # pragma: no cover
694696 return form_field
695697
696698 def get_choices (
@@ -1263,6 +1265,7 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
12631265 form_field .enum = self .enum
12641266 form_field .strict = self .strict
12651267 form_field .primitive = self .primitive
1268+ # pragma: no cover
12661269 return form_field
12671270
12681271 def get_choices (
0 commit comments