﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35887	Improve Examples for  StackedInline and TabularInline	Alexander Lazarević	Alexander Lazarević	"I think the Django admin documentation could be improved by making the examples for  StackedInline and TabularInline easier to incorporate. There are some bits and pieces missing sometimes that are not obvious.

Take the partial example to show how TabularInline is meant to be used:

{{{
from django.contrib import admin


class BookInline(admin.TabularInline):
    model = Book


class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        BookInline,
    ]
}}}

So using this, you'll soon find out that the import for the {{{Book}}} model is missing.  Easy enough to add this, but still a nuisance.

{{{
from .models import Book
}}}

Everything seems to work, but you can't see neither {{{Authors}}} nor {{{Books}}} in the admin, because the registration is missing. So you just quickly type in the code to register the {{{ModelAdmins}}} from your weak memory.

{{{
admin.register(Book, BookInline)
admin.register(Author, AuthorAdmin)
}}}

You realise the import for the {{{Author}}} model is missing as well. Ok, you just add that.

{{{
from .models import Author, Book
}}}

Everything looks fine, the server starts without any errors and again no Authors or Books in the admin.

You search through some other examples and see that you used {{{admin.register}}} instead of {{{admin.site.register}}}. After a face-palm you correct it.

{{{
admin.site.register(Book, BookInline)
admin.site.register(Author, AuthorAdmin)
}}}

Now the server puts out an error ""AttributeError: 'BookInline' object has no attribute 'urls'"".
You wonder what that's all about and after some time you find an example in the tutorial that only contains the registration for the not inlined {{{ModelAdmin}}}.

After that you got it finally working ...

I think providing the import of the models and the registration could prevent such on odyssey.

There are other places as well where some pieces are missing and it's not possible to just copy and paste the examples."	Cleanup/optimization	assigned	Documentation	dev	Normal				Unreviewed	0	0	0	0	0	0
