Forms and ModelForms in Python

From the Django cheat sheet · Forms · verified Jul 2026

Forms and ModelForms

Create and validate forms

python
from django import forms
from .models import Product

class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = ['name', 'price', 'description']
💡 clean_<field>() for field validation
📌 clean() for cross-field validation
⚡ Use widgets to customize HTML
🟢 commit=False to modify before saving
Back to the full Django cheat sheet