Ticket #13068: models.2.py

File models.2.py, 1.4 KB (added by stan <stanislas.guerra__at__gmail.com>, 13 years ago)

Simple test models/admin with fieldset set in StackedInline.

Line 
1# Cases tested:
2# - prepop field in inline add another #13608
3# - two prepop fields relying on same field #9264
4# - prepop based on calendar widget #9784
5# - prepop based on dropdown #9983
6
7from django.db import models
8
9class Question(models.Model):
10 name = models.CharField(max_length=100)
11 pubdate = models.DateField()
12 status = models.CharField(max_length=20, choices=(('option one', 'Option One'),
13 ('option two', 'Option Two')))
14 slug1 = models.SlugField()
15 slug2 = models.SlugField()
16
17 parent = models.ForeignKey('self')
18
19from django.contrib import admin
20
21class QuestionInline1(admin.StackedInline):
22 fieldsets = (
23 (None, {
24 'fields': (('pubdate', 'status'), ('name', 'slug1', 'slug2',),)
25 }),
26 )
27 model = Question
28 extra = 1
29 prepopulated_fields = {'slug1': ['name', 'pubdate'],
30 'slug2': ['status', 'name']}
31
32class QuestionInline2(admin.TabularInline):
33 model = Question
34 extra = 1
35 prepopulated_fields = {'slug1': ['name', 'pubdate'],
36 'slug2': ['status', 'name']}
37
38class QuestionAdmin(admin.ModelAdmin):
39 inlines = [QuestionInline1, QuestionInline2]
40 prepopulated_fields = {'slug1': ['name', 'pubdate'],
41 'slug2': ['status', 'name']}
42
43admin.site.register(Question, QuestionAdmin)
Back to Top