Previous Page Next Page

Form Field to Model Field Mapping

Table B.2 shows the mapping of form field objects to model field objects. This mapping is used when you use the form_for_model and form_for_instance helper functions. This table might also help you know which Field objects to use when you create custom forms.

Table B.2. Mapping of Form Field Objects to Model Field Objects
Model FieldForm Field
AutoFieldNot represented in the form
BooleanFieldBooleanField
CharFieldCharField with max_length set to the model field's max_length
CommaSeparatedIntegerFieldCharField
DateFieldDateField
DateTimeFieldDateTimeField
DecimalFieldDecimalField
EmailFieldEmailField
FileFieldFileField
FilePathFieldCharField
FloatFieldFloatField
ForeignKeyModelChoiceField
ImageFieldImageField
IntegerFieldIntegerField
IPAddressFieldIPAddressField
ManyToManyFieldModelMultipleChoiceField
NullBooleanFieldCharField
PhoneNumberFieldUSPhoneNumberField
PositiveIntegerFieldIntegerField
PositiveSmallIntegerFieldIntegerField
SlugFieldCharField
SmallIntegerFieldIntegerField
TextFieldCharField with widget=Textarea
TimeFieldTimeField
URLFieldURLField with verify_exists set equal to the model field's verify_exists
USStateFieldCharField with widget=USStateSelect
XMLFieldCharField with widget=Textarea


Did you Know?

The USStateSelect and USPhoneNumberField fields are not from the standard set of Widget objects. They are from the django.contrib.localflavor.us package. Watch for additional Widgets and other things as more features are added to Django.


When each form field is generated, Django uses the following rules to set attributes on it:

Previous Page Next Page