#35887: Improve Examples for  StackedInline and TabularInline
-------------------------------------+-------------------------------------
     Reporter:  Alexander Lazarević  |                    Owner:  Alexander
         Type:                       |  Lazarević
  Cleanup/optimization               |                   Status:  assigned
    Component:  Documentation        |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Alexander Lazarević:

Old description:

> 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.

New description:

 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}}}.

 {{{
 admin.site.register(Author, AuthorAdmin)
 }}}

 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#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070192fb0a7645-173e7638-40a1-4ab1-8279-f31560bb8e91-000000%40eu-central-1.amazonses.com.

Reply via email to