1 from django
.contrib
import admin
2 from django
import forms
6 site
= admin
.AdminSite(name
="admin")
9 class BookInline(admin
.TabularInline
):
10 model
= Author
.books
.through
13 class AuthorAdmin(admin
.ModelAdmin
):
14 inlines
= [BookInline
]
17 class InnerInline(admin
.StackedInline
):
20 readonly_fields
= ('readonly',) # For bug #13174 tests.
23 class HolderAdmin(admin
.ModelAdmin
):
26 js
= ('my_awesome_admin_scripts.js',)
29 class InnerInline2(admin
.StackedInline
):
33 js
= ('my_awesome_inline_scripts.js',)
36 class InnerInline3(admin
.StackedInline
):
40 js
= ('my_awesome_inline_scripts.js',)
43 class TitleForm(forms
.ModelForm
):
46 cleaned_data
= self
.cleaned_data
47 title1
= cleaned_data
.get("title1")
48 title2
= cleaned_data
.get("title2")
50 raise forms
.ValidationError("The two titles must be the same")
54 class TitleInline(admin
.TabularInline
):
60 class Inner4StackedInline(admin
.StackedInline
):
64 class Inner4TabularInline(admin
.TabularInline
):
68 class Holder4Admin(admin
.ModelAdmin
):
69 inlines
= [Inner4StackedInline
, Inner4TabularInline
]
72 class InlineWeakness(admin
.TabularInline
):
73 model
= ShoppingWeakness
77 class QuestionInline(admin
.TabularInline
):
79 readonly_fields
=['call_me']
81 def call_me(self
, obj
):
82 return 'Callable in QuestionInline'
85 class PollAdmin(admin
.ModelAdmin
):
86 inlines
= [QuestionInline
]
88 def call_me(self
, obj
):
89 return 'Callable in PollAdmin'
92 class ChapterInline(admin
.TabularInline
):
94 readonly_fields
=['call_me']
96 def call_me(self
, obj
):
97 return 'Callable in ChapterInline'
100 class NovelAdmin(admin
.ModelAdmin
):
101 inlines
= [ChapterInline
]
104 class ConsigliereInline(admin
.TabularInline
):
108 class SottoCapoInline(admin
.TabularInline
):
112 class ProfileInline(admin
.TabularInline
):
116 site
.register(TitleCollection
, inlines
=[TitleInline
])
117 # Test bug #12561 and #12778
118 # only ModelAdmin media
119 site
.register(Holder
, HolderAdmin
, inlines
=[InnerInline
])
120 # ModelAdmin and Inline media
121 site
.register(Holder2
, HolderAdmin
, inlines
=[InnerInline2
])
123 site
.register(Holder3
, inlines
=[InnerInline3
])
125 site
.register(Poll
, PollAdmin
)
126 site
.register(Novel
, NovelAdmin
)
127 site
.register(Fashionista
, inlines
=[InlineWeakness
])
128 site
.register(Holder4
, Holder4Admin
)
129 site
.register(Author
, AuthorAdmin
)
130 site
.register(CapoFamiglia
, inlines
=[ConsigliereInline
, SottoCapoInline
])
131 site
.register(ProfileCollection
, inlines
=[ProfileInline
])