You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an inline admin where I'm trying to override the choices used. The issue with the implementation of this method in Unfold's base in admin.py is that if you modify the choices kwarg, it will be overridden by the base choices unless you also pass the widget kwarg, and doing that requires importing some internal Unfold stuff in an unclean way.
Current
def formfield_for_choice_field(
self, db_field: Field, request: HttpRequest, **kwargs
) -> TypedChoiceField:
# Overrides widget for CharFields which have choices attribute
if "widget" not in kwargs:
if db_field.name in self.radio_fields:
kwargs["widget"] = UnfoldAdminRadioSelectWidget(
radio_style=self.radio_fields[db_field.name]
)
else:
kwargs["widget"] = UnfoldAdminSelectWidget()
kwargs["choices"] = db_field.get_choices(
include_blank=db_field.blank, blank_choice=[("", _("Select value"))]
)
return super().formfield_for_choice_field(db_field, request, **kwargs)
What it should be
def formfield_for_choice_field(
self, db_field: Field, request: HttpRequest, **kwargs
) -> TypedChoiceField:
if "widget" not in kwargs:
if db_field.name in self.radio_fields:
kwargs["widget"] = UnfoldAdminRadioSelectWidget(
radio_style=self.radio_fields[db_field.name]
)
else:
kwargs["widget"] = UnfoldAdminSelectWidget()
if "choices" not in kwargs:
kwargs["choices"] = db_field.get_choices(
include_blank=db_field.blank, blank_choice=[("", _("Select value"))]
)
return super().formfield_for_choice_field(db_field, request, **kwargs)
The text was updated successfully, but these errors were encountered:
I have an inline admin where I'm trying to override the choices used. The issue with the implementation of this method in Unfold's base in
admin.py
is that if you modify thechoices
kwarg, it will be overridden by the base choices unless you also pass the widget kwarg, and doing that requires importing some internal Unfold stuff in an unclean way.Current
What it should be
The text was updated successfully, but these errors were encountered: