MCPcopy
hub / github.com/django/django / formfield

Method formfield

django/db/models/fields/__init__.py:1233–1243  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

1231 return self.to_python(value)
1232
1233 def formfield(self, **kwargs):
1234 if self.choices is not None:
1235 include_blank = not (self.has_default() or "initial" in kwargs)
1236 defaults = {"choices": self.get_choices(include_blank=include_blank)}
1237 else:
1238 form_class = forms.NullBooleanField if self.null else forms.BooleanField
1239 # In HTML checkboxes, 'required' means "must be checked" which is
1240 # different from the choices case ("must select some value").
1241 # required=False allows unchecked checkboxes.
1242 defaults = {"form_class": form_class, "required": False}
1243 return super().formfield(**{**defaults, **kwargs})
1244
1245
1246class CharField(Field):

Calls 3

has_defaultMethod · 0.80
get_choicesMethod · 0.45
formfieldMethod · 0.45