MCPcopy
hub / github.com/django/django / formfield_for_choice_field

Method formfield_for_choice_field

django/contrib/admin/options.py:278–295  ·  view source on GitHub ↗

Get a form Field for a database Field that has declared choices.

(self, db_field, request, **kwargs)

Source from the content-addressed store, hash-verified

276 return db_field.formfield(**kwargs)
277
278 def formfield_for_choice_field(self, db_field, request, **kwargs):
279 """
280 Get a form Field for a database Field that has declared choices.
281 """
282 # If the field is named as a radio_field, use a RadioSelect
283 if db_field.name in self.radio_fields:
284 # Avoid stomping on custom widget/choices arguments.
285 if "widget" not in kwargs:
286 kwargs["widget"] = widgets.AdminRadioSelect(
287 attrs={
288 "class": get_ul_class(self.radio_fields[db_field.name]),
289 }
290 )
291 if "choices" not in kwargs:
292 kwargs["choices"] = db_field.get_choices(
293 include_blank=db_field.blank, blank_choice=[("", _("None"))]
294 )
295 return db_field.formfield(**kwargs)
296
297 def get_field_queryset(self, db, db_field, request):
298 """

Callers 1

formfield_for_dbfieldMethod · 0.95

Calls 3

get_ul_classFunction · 0.85
get_choicesMethod · 0.45
formfieldMethod · 0.45

Tested by

no test coverage detected