Introduction
Django Unfold provides a complete form system that extends Django’s admin forms with modern, styled components. The forms system includes custom widgets, fields, formsets with pagination, and seamless integration with Django’s admin interface.Key Features
Custom Widgets
Pre-styled form widgets matching Unfold’s design system
Custom Fields
Enhanced form fields with autocomplete and special functionality
Pagination Support
Built-in pagination for inline formsets
Conditional Fields
Show/hide fields based on conditions
Form Classes
AdminForm
Unfold provides custom form wrapper classes that integrate with Django’s admin system:The
AdminForm, Fieldset, and Fieldline classes are automatically applied when using Unfold’s ModelAdmin. They handle the rendering of form fields with proper styling.Authentication Forms
Custom authentication forms with Unfold styling:Example: Custom Login Form
admin.py
ActionForm
Custom action form for admin list views:Formset Pagination
PaginationInlineFormSet
Paginate inline formsets to improve performance with large datasets:admin.py
PaginationGenericInlineFormSet
Pagination support for generic inline formsets:admin.py
Form Field Styling
All Unfold widgets come with pre-applied Tailwind CSS classes:Search Forms
DatasetChangeListSearchForm
Custom search form for dataset change lists:Form Validation
Unfold forms display validation errors with proper styling:forms.py
Validation errors are automatically styled with red borders and error messages below the field.
Password Fields
UnfoldReadOnlyPasswordHashWidget
Read-only widget for displaying password hashes:Best Practices
Use Unfold Widgets
Use Unfold Widgets
Always use Unfold’s custom widgets to maintain consistent styling across your admin interface.
Paginate Large Formsets
Paginate Large Formsets
Use
PaginationInlineFormSet for inline relationships with many related objects to improve performance.Leverage Autocomplete
Leverage Autocomplete
Use autocomplete fields for foreign key relationships to improve user experience with large datasets.
Validate Properly
Validate Properly
Implement custom validation methods to provide clear feedback to users.
Next Steps
Custom Widgets
Explore all available form widgets
Custom Fields
Learn about enhanced form fields
Conditional Fields
Implement conditional field visibility
Crispy Forms
Integrate with Django Crispy Forms