#35887: Improve Examples for StackedInline and TabularInline
-------------------------------------+-------------------------------------
Reporter: Alexander | Owner: Alexander Lazarević
Lazarević |
Type: | Status: assigned
Cleanup/optimization |
Component: | Version: dev
Documentation |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35887>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.