summaryrefslogtreecommitdiffstats
path: root/polls/models.py
blob: f8a1b1738b4242094dbbc37779fd9fc9b2f4506f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.db import models

# Create your models here.

class Poll(models.Model):
	def __unicode__(self):
		return self.question
        question = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')

class Choice(models.Model):
	def __unicode__(self):
                return self.choice
        poll = models.ForeignKey(Poll)
        choice = models.CharField(max_length=200)
	votes = models.IntegerField()

from django.contrib import admin

class ChoiceInline(admin.TabularInline):
	model = Choice
	extra = 3

class PollAdmin(admin.ModelAdmin):
	list_display = ('question', 'pub_date')
	list_filter = ['pub_date']
	search_fields = ['question']
	date_hierarchy = 'pub_date'
        fieldsets = [
            (None,               {'fields': ['question']}),
            ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
        ]
	inlines = [ChoiceInline]

admin.site.register(Poll, PollAdmin)