App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / regressiontests / admin_inlines / admin.py
blob508f30223f977353812900a9a2682ea5b38b696a
1 from django.contrib import admin
2 from django import forms
4 from models import *
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):
18 model = Inner
19 can_delete = False
20 readonly_fields = ('readonly',) # For bug #13174 tests.
23 class HolderAdmin(admin.ModelAdmin):
25 class Media:
26 js = ('my_awesome_admin_scripts.js',)
29 class InnerInline2(admin.StackedInline):
30 model = Inner2
32 class Media:
33 js = ('my_awesome_inline_scripts.js',)
36 class InnerInline3(admin.StackedInline):
37 model = Inner3
39 class Media:
40 js = ('my_awesome_inline_scripts.js',)
43 class TitleForm(forms.ModelForm):
45 def clean(self):
46 cleaned_data = self.cleaned_data
47 title1 = cleaned_data.get("title1")
48 title2 = cleaned_data.get("title2")
49 if title1 != title2:
50 raise forms.ValidationError("The two titles must be the same")
51 return cleaned_data
54 class TitleInline(admin.TabularInline):
55 model = Title
56 form = TitleForm
57 extra = 1
60 class Inner4StackedInline(admin.StackedInline):
61 model = Inner4Stacked
64 class Inner4TabularInline(admin.TabularInline):
65 model = Inner4Tabular
68 class Holder4Admin(admin.ModelAdmin):
69 inlines = [Inner4StackedInline, Inner4TabularInline]
72 class InlineWeakness(admin.TabularInline):
73 model = ShoppingWeakness
74 extra = 1
77 class QuestionInline(admin.TabularInline):
78 model = Question
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):
93 model = Chapter
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):
105 model = Consigliere
108 class SottoCapoInline(admin.TabularInline):
109 model = SottoCapo
112 class ProfileInline(admin.TabularInline):
113 model = Profile
114 extra = 1
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])
122 # only Inline media
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])