| 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 | model = Question
|
|---|
| 23 | extra = 1
|
|---|
| 24 | prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
|---|
| 25 | 'slug2': ['status', 'name']}
|
|---|
| 26 |
|
|---|
| 27 | class QuestionInline2(admin.TabularInline):
|
|---|
| 28 | model = Question
|
|---|
| 29 | extra = 1
|
|---|
| 30 | prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
|---|
| 31 | 'slug2': ['status', 'name']}
|
|---|
| 32 |
|
|---|
| 33 | class QuestionAdmin(admin.ModelAdmin):
|
|---|
| 34 | inlines = [QuestionInline1, QuestionInline2]
|
|---|
| 35 | prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
|---|
| 36 | 'slug2': ['status', 'name']}
|
|---|
| 37 |
|
|---|
| 38 | admin.site.register(Question, QuestionAdmin)
|
|---|