summaryrefslogtreecommitdiffstats
path: root/polls/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'polls/models.py')
-rwxr-xr-xpolls/models.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/polls/models.py b/polls/models.py
new file mode 100755
index 0000000..f8a1b17
--- /dev/null
+++ b/polls/models.py
@@ -0,0 +1,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)