Inlines and Readonly Fields
Edit related rows inline and protect fields.
Inlines and Readonly Fields is a free Django Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Edit Related Rows Together
Sometimes related records belong on the same page. An inline lets you edit child rows right inside their parent's edit form. 🧩
Two Inline Styles
Django offers two layouts. A TabularInline shows rows in a compact table, while StackedInline stacks each row as its own block.
Define an Inline
Create a small class that subclasses TabularInline and points its model attribute at the child model you want to embed.
class CommentInline(admin.TabularInline):
model = CommentAttach to the Parent
List your inline on the parent's admin. The inlines option tells Django to render those child rows inside the parent form.
class PostAdmin(admin.ModelAdmin):
inlines = [CommentInline]Spare Blank Rows
Inlines show empty rows for quick adding. Set extra to control how many blank slots appear, often just one is enough.
extra = 1The FK Requirement
Inlines only work when the child has a ForeignKey to the parent. That link is how Django knows which rows belong together.
Protect a Field
Some values should be visible but never edited by hand. Add them to readonly_fields and the admin shows them locked. 🔒
readonly_fields = ("created", "updated")Auto Timestamps
Fields like an auto_now_add date are set by Django, not people. Marking them readonly avoids confusing, unsaveable edits.
Show a Computed Value
readonly_fields can name a method too, letting you display a calculated value that has no real database column.
def word_count(self, obj):
return len(obj.body.split())Readonly Inside Inlines
Inlines accept readonly_fields as well. Use it to display child data clearly while keeping sensitive columns uneditable.
Permissions Still Apply
Readonly is about the form, not security. Real access is governed by user permissions, so combine both for safe editing.
Quick Check
What is required for a model to appear as an inline?
Recap
You embedded related rows with inlines and locked sensitive values using readonly_fields. Together they make admin editing rich yet safe. ✅
Frequently asked questions
Is the “Inlines and Readonly Fields” lesson free?
Yes — the full text of “Inlines and Readonly Fields” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “Inlines and Readonly Fields”?
Edit related rows inline and protect fields. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Inlines and Readonly Fields” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- createsuperuser and Logging In
- Registering Models with admin.site
- Customizing ModelAdmin
- Inlines and Readonly Fields