2011-09-20 18:16:49 +00:00
|
|
|
from django.contrib import admin
|
|
|
|
from django import forms
|
|
|
|
|
|
|
|
from models import *
|
|
|
|
|
|
|
|
site = admin.AdminSite(name="admin")
|
|
|
|
|
|
|
|
|
|
|
|
class BookInline(admin.TabularInline):
|
|
|
|
model = Author.books.through
|
|
|
|
|
|
|
|
|
|
|
|
class AuthorAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [BookInline]
|
|
|
|
|
|
|
|
|
|
|
|
class InnerInline(admin.StackedInline):
|
|
|
|
model = Inner
|
|
|
|
can_delete = False
|
|
|
|
readonly_fields = ('readonly',) # For bug #13174 tests.
|
|
|
|
|
|
|
|
|
|
|
|
class HolderAdmin(admin.ModelAdmin):
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_admin_scripts.js',)
|
|
|
|
|
|
|
|
|
|
|
|
class InnerInline2(admin.StackedInline):
|
|
|
|
model = Inner2
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_inline_scripts.js',)
|
|
|
|
|
|
|
|
|
|
|
|
class InnerInline3(admin.StackedInline):
|
|
|
|
model = Inner3
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_inline_scripts.js',)
|
|
|
|
|
|
|
|
|
|
|
|
class TitleForm(forms.ModelForm):
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = self.cleaned_data
|
|
|
|
title1 = cleaned_data.get("title1")
|
|
|
|
title2 = cleaned_data.get("title2")
|
|
|
|
if title1 != title2:
|
|
|
|
raise forms.ValidationError("The two titles must be the same")
|
|
|
|
return cleaned_data
|
|
|
|
|
|
|
|
|
|
|
|
class TitleInline(admin.TabularInline):
|
|
|
|
model = Title
|
|
|
|
form = TitleForm
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
|
|
|
|
class Inner4StackedInline(admin.StackedInline):
|
|
|
|
model = Inner4Stacked
|
|
|
|
|
|
|
|
|
|
|
|
class Inner4TabularInline(admin.TabularInline):
|
|
|
|
model = Inner4Tabular
|
|
|
|
|
|
|
|
|
|
|
|
class Holder4Admin(admin.ModelAdmin):
|
|
|
|
inlines = [Inner4StackedInline, Inner4TabularInline]
|
|
|
|
|
|
|
|
|
|
|
|
class InlineWeakness(admin.TabularInline):
|
|
|
|
model = ShoppingWeakness
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
|
|
|
|
class QuestionInline(admin.TabularInline):
|
|
|
|
model = Question
|
|
|
|
readonly_fields=['call_me']
|
|
|
|
|
|
|
|
def call_me(self, obj):
|
|
|
|
return 'Callable in QuestionInline'
|
|
|
|
|
|
|
|
|
|
|
|
class PollAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [QuestionInline]
|
|
|
|
|
|
|
|
def call_me(self, obj):
|
|
|
|
return 'Callable in PollAdmin'
|
|
|
|
|
|
|
|
|
|
|
|
class ChapterInline(admin.TabularInline):
|
|
|
|
model = Chapter
|
|
|
|
readonly_fields=['call_me']
|
|
|
|
|
|
|
|
def call_me(self, obj):
|
|
|
|
return 'Callable in ChapterInline'
|
|
|
|
|
|
|
|
|
|
|
|
class NovelAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [ChapterInline]
|
|
|
|
|
|
|
|
|
2011-09-21 14:00:58 +00:00
|
|
|
class ConsigliereInline(admin.TabularInline):
|
|
|
|
model = Consigliere
|
|
|
|
|
|
|
|
|
|
|
|
class SottoCapoInline(admin.TabularInline):
|
|
|
|
model = SottoCapo
|
|
|
|
|
|
|
|
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 08:33:58 +00:00
|
|
|
class ProfileInline(admin.TabularInline):
|
|
|
|
model = Profile
|
|
|
|
extra = 1
|
|
|
|
|
2011-09-20 18:16:49 +00:00
|
|
|
site.register(TitleCollection, inlines=[TitleInline])
|
|
|
|
# Test bug #12561 and #12778
|
|
|
|
# only ModelAdmin media
|
|
|
|
site.register(Holder, HolderAdmin, inlines=[InnerInline])
|
|
|
|
# ModelAdmin and Inline media
|
|
|
|
site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
|
|
|
|
# only Inline media
|
|
|
|
site.register(Holder3, inlines=[InnerInline3])
|
|
|
|
|
|
|
|
site.register(Poll, PollAdmin)
|
|
|
|
site.register(Novel, NovelAdmin)
|
|
|
|
site.register(Fashionista, inlines=[InlineWeakness])
|
|
|
|
site.register(Holder4, Holder4Admin)
|
|
|
|
site.register(Author, AuthorAdmin)
|
2011-09-21 14:00:58 +00:00
|
|
|
site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline])
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 08:33:58 +00:00
|
|
|
site.register(ProfileCollection, inlines=[ProfileInline])
|