Declaring a ModelForm and Meta.fields
Bind a form to a model in a few lines.
Why ModelForm Exists
You already have a model describing your data. A ModelForm builds a form straight from that model, so you never repeat the same fields twice. 🎯
Import ModelForm
ModelForms live in the same place as regular forms. You subclass forms.ModelForm instead of forms.Form to get the model-aware version.
from django import forms
from .models import PostAll lessons in this course
- Declaring a ModelForm and Meta.fields
- form.save() and commit=False
- Custom Validation with clean methods
- Widgets, Labels, and Help Text