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 |
|
---|
7 | from django.db import models
|
---|
8 |
|
---|
9 | class 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 |
|
---|
19 | from django.contrib import admin
|
---|
20 |
|
---|
21 | class 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 |
|
---|
32 | class QuestionInline2(admin.TabularInline):
|
---|
33 | model = Question
|
---|
34 | extra = 1
|
---|
35 | prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
---|
36 | 'slug2': ['status', 'name']}
|
---|
37 |
|
---|
38 | class QuestionAdmin(admin.ModelAdmin):
|
---|
39 | inlines = [QuestionInline1, QuestionInline2]
|
---|
40 | prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
---|
41 | 'slug2': ['status', 'name']}
|
---|
42 |
|
---|
43 | admin.site.register(Question, QuestionAdmin)
|
---|