Commits

Jeff Hardy committed c4c77f2

Improve admin functionality for Poll app

Comments (0)

Files changed (2)

mysite/polls/admin.py

-from mysite.polls.models import Poll
+from mysite.polls.models import Poll, Choice
 from django.contrib import admin
 
-admin.site.register(Poll)
+class ChoiceInline(admin.TabularInline):
+    model = Choice
+    extra = 3
+
+class PollAdmin(admin.ModelAdmin):
+    fieldsets = [
+        (None,               {'fields': ['question']}),
+        ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
+    ]
+    inlines = [ChoiceInline]
+    list_display = ('question', 'pub_date', 'was_published_today')
+    list_filter = ['pub_date']
+    search_fields = ['question']
+    date_hierarchy = 'pub_date'
+
+admin.site.register(Poll, PollAdmin)

mysite/polls/models.py

 
     def was_published_today(self):
         return self.pub_date.date() == datetime.date.today()
+    was_published_today.short_description = 'Published today?'
 
     def __unicode__(self):
         return self.question