|
2 | 2 | from .models import Poll, Choice, Vote
|
3 | 3 |
|
4 | 4 |
|
| 5 | +class ChoiceInline(admin.TabularInline): # or admin.StackedInline for a different layout |
| 6 | + model = Choice |
| 7 | + extra = 1 |
| 8 | + |
5 | 9 | @admin.register(Poll)
|
6 | 10 | class PollAdmin(admin.ModelAdmin):
|
7 |
| - list_display = ["text", "owner", "pub_date", "active"] |
| 11 | + list_display = ["text", "owner", "pub_date", "active", "created_at"] |
8 | 12 | search_fields = ["text", "owner__username"]
|
9 |
| - list_filter = ["active"] |
| 13 | + list_filter = ["active", 'created_at', 'pub_date'] |
10 | 14 | date_hierarchy = "pub_date"
|
| 15 | + inlines = [ChoiceInline] |
11 | 16 |
|
12 | 17 |
|
13 | 18 | @admin.register(Choice)
|
14 | 19 | class ChoiceAdmin(admin.ModelAdmin):
|
15 |
| - list_display = ["choice_text", "poll"] |
| 20 | + list_display = ["choice_text", "poll", 'created_at', 'updated_at'] |
16 | 21 | search_fields = ["choice_text", "poll__text"]
|
17 | 22 | autocomplete_fields = ["poll"]
|
18 | 23 |
|
19 | 24 |
|
20 | 25 | @admin.register(Vote)
|
21 | 26 | class VoteAdmin(admin.ModelAdmin):
|
22 |
| - list_display = ["choice", "poll", "user"] |
| 27 | + list_display = ["choice", "poll", "user", 'created_at'] |
23 | 28 | search_fields = ["choice__choice_text", "poll__text", "user__username"]
|
24 | 29 | autocomplete_fields = ["choice", "poll", "user"]
|
0 commit comments