1 | from django.db import models
|
---|
2 | from django.contrib import admin
|
---|
3 |
|
---|
4 | class Poll(models.Model):
|
---|
5 | question = models.CharField(max_length=200)
|
---|
6 | pub_date = models.DateTimeField('date published')
|
---|
7 |
|
---|
8 | class Choice(models.Model):
|
---|
9 | poll = models.ForeignKey(Poll)
|
---|
10 | # choice = models.CharField(max_length=200)
|
---|
11 | votes = models.IntegerField()
|
---|
12 |
|
---|
13 | class ChoiceInline(admin.TabularInline):
|
---|
14 | model = Choice
|
---|
15 | extra = 3
|
---|
16 |
|
---|
17 | class PollAdmin(admin.ModelAdmin):
|
---|
18 | fields = ['pub_date', 'question']
|
---|
19 | inlines = [ChoiceInline]
|
---|
20 |
|
---|
21 | admin.site.register(Poll, PollAdmin)
|
---|