0PricingLogin
Django Academy · Lesson

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 Post

All lessons in this course

  1. Declaring a ModelForm and Meta.fields
  2. form.save() and commit=False
  3. Custom Validation with clean methods
  4. Widgets, Labels, and Help Text
← Back to Django Academy