2011-09-21 02:16:49 +08:00
|
|
|
from django import forms
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.contrib import admin
|
2017-12-01 04:19:02 +08:00
|
|
|
from django.db import models
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2013-10-22 20:28:34 +08:00
|
|
|
from .models import (
|
2019-05-11 18:30:19 +08:00
|
|
|
Author, BinaryTree, CapoFamiglia, Chapter, Child, ChildModel1, ChildModel2,
|
2019-05-29 01:57:31 +08:00
|
|
|
Consigliere, EditablePKBook, ExtraTerrestrial, Fashionista, FootNote,
|
|
|
|
Holder, Holder2, Holder3, Holder4, Inner, Inner2, Inner3, Inner4Stacked,
|
2017-06-10 08:54:10 +08:00
|
|
|
Inner4Tabular, NonAutoPKBook, NonAutoPKBookChild, Novel,
|
2019-05-29 01:57:31 +08:00
|
|
|
NovelReadonlyChapter, OutfitItem, ParentModelWithCustomPk, Poll, Profile,
|
2018-05-19 07:50:58 +08:00
|
|
|
ProfileCollection, Question, ReadOnlyInline, ShoppingWeakness, Sighting,
|
2019-05-11 18:30:19 +08:00
|
|
|
SomeChildModel, SomeParentModel, SottoCapo, Teacher, Title,
|
|
|
|
TitleCollection,
|
2013-10-22 20:28:34 +08:00
|
|
|
)
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
site = admin.AdminSite(name="admin")
|
|
|
|
|
|
|
|
|
|
|
|
class BookInline(admin.TabularInline):
|
|
|
|
model = Author.books.through
|
|
|
|
|
|
|
|
|
2013-07-20 03:55:16 +08:00
|
|
|
class NonAutoPKBookTabularInline(admin.TabularInline):
|
|
|
|
model = NonAutoPKBook
|
2015-11-07 23:46:50 +08:00
|
|
|
classes = ('collapse',)
|
2013-07-20 03:55:16 +08:00
|
|
|
|
|
|
|
|
2017-06-10 08:54:10 +08:00
|
|
|
class NonAutoPKBookChildTabularInline(admin.TabularInline):
|
|
|
|
model = NonAutoPKBookChild
|
|
|
|
classes = ('collapse',)
|
|
|
|
|
|
|
|
|
2013-07-20 03:55:16 +08:00
|
|
|
class NonAutoPKBookStackedInline(admin.StackedInline):
|
|
|
|
model = NonAutoPKBook
|
2015-11-07 23:46:50 +08:00
|
|
|
classes = ('collapse',)
|
2013-07-20 03:55:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
class EditablePKBookTabularInline(admin.TabularInline):
|
|
|
|
model = EditablePKBook
|
|
|
|
|
|
|
|
|
|
|
|
class EditablePKBookStackedInline(admin.StackedInline):
|
|
|
|
model = EditablePKBook
|
|
|
|
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
class AuthorAdmin(admin.ModelAdmin):
|
2016-04-08 10:04:45 +08:00
|
|
|
inlines = [
|
|
|
|
BookInline, NonAutoPKBookTabularInline, NonAutoPKBookStackedInline,
|
|
|
|
EditablePKBookTabularInline, EditablePKBookStackedInline,
|
2017-06-10 08:54:10 +08:00
|
|
|
NonAutoPKBookChildTabularInline,
|
2016-04-08 10:04:45 +08:00
|
|
|
]
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
class InnerInline(admin.StackedInline):
|
|
|
|
model = Inner
|
|
|
|
can_delete = False
|
2013-11-03 05:02:56 +08:00
|
|
|
readonly_fields = ('readonly',) # For bug #13174 tests.
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
class HolderAdmin(admin.ModelAdmin):
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_admin_scripts.js',)
|
|
|
|
|
|
|
|
|
2013-02-24 01:24:32 +08:00
|
|
|
class ReadOnlyInlineInline(admin.TabularInline):
|
|
|
|
model = ReadOnlyInline
|
|
|
|
readonly_fields = ['name']
|
|
|
|
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
class InnerInline2(admin.StackedInline):
|
|
|
|
model = Inner2
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_inline_scripts.js',)
|
|
|
|
|
|
|
|
|
2018-08-09 23:43:55 +08:00
|
|
|
class InnerInline2Tabular(admin.TabularInline):
|
|
|
|
model = Inner2
|
|
|
|
|
|
|
|
|
2017-12-01 04:19:02 +08:00
|
|
|
class CustomNumberWidget(forms.NumberInput):
|
|
|
|
class Media:
|
|
|
|
js = ('custom_number.js',)
|
|
|
|
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
class InnerInline3(admin.StackedInline):
|
|
|
|
model = Inner3
|
2017-12-01 04:19:02 +08:00
|
|
|
formfield_overrides = {
|
|
|
|
models.IntegerField: {'widget': CustomNumberWidget},
|
|
|
|
}
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_inline_scripts.js',)
|
|
|
|
|
|
|
|
|
|
|
|
class TitleForm(forms.ModelForm):
|
2015-10-07 07:01:39 +08:00
|
|
|
title1 = forms.CharField(max_length=100)
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
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
|
2014-07-25 20:07:04 +08:00
|
|
|
show_change_link = True
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Inner4TabularInline(admin.TabularInline):
|
|
|
|
model = Inner4Tabular
|
2014-07-25 20:07:04 +08:00
|
|
|
show_change_link = True
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Holder4Admin(admin.ModelAdmin):
|
|
|
|
inlines = [Inner4StackedInline, Inner4TabularInline]
|
|
|
|
|
|
|
|
|
|
|
|
class InlineWeakness(admin.TabularInline):
|
|
|
|
model = ShoppingWeakness
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
|
2019-05-29 01:57:31 +08:00
|
|
|
class WeaknessForm(forms.ModelForm):
|
|
|
|
extra_field = forms.CharField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ShoppingWeakness
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
|
|
|
|
class WeaknessInlineCustomForm(admin.TabularInline):
|
|
|
|
model = ShoppingWeakness
|
|
|
|
form = WeaknessForm
|
|
|
|
|
|
|
|
|
|
|
|
class FootNoteForm(forms.ModelForm):
|
|
|
|
extra_field = forms.CharField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = FootNote
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
|
|
|
|
class FootNoteNonEditableInlineCustomForm(admin.TabularInline):
|
|
|
|
model = FootNote
|
|
|
|
form = FootNoteForm
|
|
|
|
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
class QuestionInline(admin.TabularInline):
|
|
|
|
model = Question
|
2013-10-23 18:09:29 +08:00
|
|
|
readonly_fields = ['call_me']
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
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
|
2013-10-23 18:09:29 +08:00
|
|
|
readonly_fields = ['call_me']
|
2011-09-21 02:16:49 +08:00
|
|
|
|
|
|
|
def call_me(self, obj):
|
|
|
|
return 'Callable in ChapterInline'
|
|
|
|
|
|
|
|
|
|
|
|
class NovelAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [ChapterInline]
|
|
|
|
|
|
|
|
|
2018-05-19 07:50:58 +08:00
|
|
|
class ReadOnlyChapterInline(admin.TabularInline):
|
|
|
|
model = Chapter
|
|
|
|
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class NovelReadonlyChapterAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [ReadOnlyChapterInline]
|
|
|
|
|
|
|
|
|
2011-09-21 22:00:58 +08: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 16:33:58 +08:00
|
|
|
class ProfileInline(admin.TabularInline):
|
|
|
|
model = Profile
|
|
|
|
extra = 1
|
|
|
|
|
2012-06-08 01:52:13 +08:00
|
|
|
|
|
|
|
# admin for #18433
|
|
|
|
class ChildModel1Inline(admin.TabularInline):
|
|
|
|
model = ChildModel1
|
|
|
|
|
|
|
|
|
|
|
|
class ChildModel2Inline(admin.StackedInline):
|
|
|
|
model = ChildModel2
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-06-02 06:16:57 +08:00
|
|
|
# admin for #19425 and #18388
|
2013-05-31 01:48:10 +08:00
|
|
|
class BinaryTreeAdmin(admin.TabularInline):
|
|
|
|
model = BinaryTree
|
|
|
|
|
|
|
|
def get_extra(self, request, obj=None, **kwargs):
|
|
|
|
extra = 2
|
|
|
|
if obj:
|
|
|
|
return extra - obj.binarytree_set.count()
|
|
|
|
return extra
|
|
|
|
|
2013-06-02 06:16:57 +08:00
|
|
|
def get_max_num(self, request, obj=None, **kwargs):
|
|
|
|
max_num = 3
|
|
|
|
if obj:
|
|
|
|
return max_num - obj.binarytree_set.count()
|
|
|
|
return max_num
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-12-29 06:16:13 +08:00
|
|
|
# admin for #19524
|
|
|
|
class SightingInline(admin.TabularInline):
|
|
|
|
model = Sighting
|
2012-06-08 01:52:13 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-10-08 00:30:02 +08:00
|
|
|
# admin and form for #18263
|
|
|
|
class SomeChildModelForm(forms.ModelForm):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = '__all__'
|
|
|
|
model = SomeChildModel
|
|
|
|
widgets = {
|
|
|
|
'position': forms.HiddenInput,
|
|
|
|
}
|
2018-03-09 06:19:02 +08:00
|
|
|
labels = {'readonly_field': 'Label from ModelForm.Meta'}
|
|
|
|
help_texts = {'readonly_field': 'Help text from ModelForm.Meta'}
|
2013-10-08 00:30:02 +08:00
|
|
|
|
2016-06-19 10:03:25 +08:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(*args, **kwargs)
|
2016-06-19 10:03:25 +08:00
|
|
|
self.fields['name'].label = 'new label'
|
|
|
|
|
2013-10-08 00:30:02 +08:00
|
|
|
|
|
|
|
class SomeChildModelInline(admin.TabularInline):
|
|
|
|
model = SomeChildModel
|
|
|
|
form = SomeChildModelForm
|
2018-03-09 06:19:02 +08:00
|
|
|
readonly_fields = ('readonly_field',)
|
2013-10-08 00:30:02 +08:00
|
|
|
|
|
|
|
|
2019-05-11 18:30:19 +08:00
|
|
|
class StudentInline(admin.StackedInline):
|
|
|
|
model = Child
|
|
|
|
extra = 1
|
|
|
|
fieldsets = [
|
|
|
|
('Name', {'fields': ('name',), 'classes': ('collapse',)}),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class TeacherAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [StudentInline]
|
|
|
|
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
site.register(TitleCollection, inlines=[TitleInline])
|
|
|
|
# Test bug #12561 and #12778
|
|
|
|
# only ModelAdmin media
|
|
|
|
site.register(Holder, HolderAdmin, inlines=[InnerInline])
|
|
|
|
# ModelAdmin and Inline media
|
2018-08-09 23:43:55 +08:00
|
|
|
site.register(Holder2, HolderAdmin, inlines=[InnerInline2, InnerInline2Tabular])
|
2011-09-21 02:16:49 +08:00
|
|
|
# only Inline media
|
|
|
|
site.register(Holder3, inlines=[InnerInline3])
|
|
|
|
|
|
|
|
site.register(Poll, PollAdmin)
|
|
|
|
site.register(Novel, NovelAdmin)
|
2018-05-19 07:50:58 +08:00
|
|
|
site.register(NovelReadonlyChapter, NovelReadonlyChapterAdmin)
|
2011-09-21 02:16:49 +08:00
|
|
|
site.register(Fashionista, inlines=[InlineWeakness])
|
|
|
|
site.register(Holder4, Holder4Admin)
|
|
|
|
site.register(Author, AuthorAdmin)
|
2013-02-24 01:24:32 +08:00
|
|
|
site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline, ReadOnlyInlineInline])
|
2012-06-08 01:52:13 +08:00
|
|
|
site.register(ProfileCollection, inlines=[ProfileInline])
|
2012-12-29 06:16:13 +08:00
|
|
|
site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
|
2013-05-31 01:48:10 +08:00
|
|
|
site.register(BinaryTree, inlines=[BinaryTreeAdmin])
|
2012-12-29 06:16:13 +08:00
|
|
|
site.register(ExtraTerrestrial, inlines=[SightingInline])
|
2013-10-08 00:30:02 +08:00
|
|
|
site.register(SomeParentModel, inlines=[SomeChildModelInline])
|
2014-07-25 20:07:04 +08:00
|
|
|
site.register([Question, Inner4Stacked, Inner4Tabular])
|
2019-05-11 18:30:19 +08:00
|
|
|
site.register(Teacher, TeacherAdmin)
|
2019-05-29 01:57:31 +08:00
|
|
|
site.register(Chapter, inlines=[FootNoteNonEditableInlineCustomForm])
|
|
|
|
site.register(OutfitItem, inlines=[WeaknessInlineCustomForm])
|