Skip to content

Commit 1084a2a

Browse files
committed
Customize the admin change list
Modified polls/admin.py and polls/models.py https://docs.djangoproject.com/en/1.8/intro/tutorial02/#customize-the-admin-change-list
1 parent e44749a commit 1084a2a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

mysite/polls/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ class QuestionAdmin(admin.ModelAdmin):
1414
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
1515
]
1616
inlines = [ChoiceInline]
17+
list_display = ('question_text', 'pub_date', 'was_published_recently')
18+
list_filter = ['pub_date']
19+
search_fields = ['question_text']
1720

1821
admin.site.register(Question, QuestionAdmin)

mysite/polls/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def __unicode__(self): # __str__ on Python 3
1313

1414
def was_published_recently(self):
1515
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
16+
was_published_recently.admin_order_field = 'pub_date'
17+
was_published_recently.boolean = True
18+
was_published_recently.short_description = 'Published recently?'
1619

1720

1821
class Choice(models.Model):

0 commit comments

Comments
 (0)