Menu

Django Admin: Group Fields Neatly with fieldsets and Auto-Generate Slugs with prepopulated_fields in 5 Minutes
📰

Django Admin: Group Fields Neatly with fieldsets and Auto-Generate Slugs with prepopulated_fields in 5 Minutes

DEV Community: django·Linh Fish Dev·about 23 hours ago
#rgT9x1qw
#devtodjango#devto#dev#django#admin
Reading 0:00
15s threshold

When a model has 10–15 fields, its edit page in Django admin becomes one endless column: title, slug, content, category, publish date, and status flags all jumbled together. The fix is fieldsets to group fields into titled, collapsible sections, combined with prepopulated_fields so the slug fills itself in from the title without typing. Both only need to be declared in ModelAdmin .

The Problem

By default, Django admin shows every field of a model in declaration order, stacked in a single column. For an article model with many fields, the edit page drags on forever: important fields like the title sit next to rarely used ones like the publish date. Worse, the slug field usually has to be typed by hand — a wrong format, a duplicate of an old slug, or a forgotten value all cause errors on save.

# admin.py — default: every field stacked in one long column from django.contrib import admin from .models import Article

@admin.register ( Article ) class ArticleAdmin ( admin .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.