Skip to content

Commit e4bf60a

Browse files
committed
feat: added inline choices
1 parent 5a63f9d commit e4bf60a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

polls/admin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22
from .models import Poll, Choice, Vote
33

44

5+
class ChoiceInline(admin.TabularInline): # or admin.StackedInline for a different layout
6+
model = Choice
7+
extra = 1
8+
59
@admin.register(Poll)
610
class PollAdmin(admin.ModelAdmin):
7-
list_display = ["text", "owner", "pub_date", "active"]
11+
list_display = ["text", "owner", "pub_date", "active", "created_at"]
812
search_fields = ["text", "owner__username"]
9-
list_filter = ["active"]
13+
list_filter = ["active", 'created_at', 'pub_date']
1014
date_hierarchy = "pub_date"
15+
inlines = [ChoiceInline]
1116

1217

1318
@admin.register(Choice)
1419
class ChoiceAdmin(admin.ModelAdmin):
15-
list_display = ["choice_text", "poll"]
20+
list_display = ["choice_text", "poll", 'created_at', 'updated_at']
1621
search_fields = ["choice_text", "poll__text"]
1722
autocomplete_fields = ["poll"]
1823

1924

2025
@admin.register(Vote)
2126
class VoteAdmin(admin.ModelAdmin):
22-
list_display = ["choice", "poll", "user"]
27+
list_display = ["choice", "poll", "user", 'created_at']
2328
search_fields = ["choice__choice_text", "poll__text", "user__username"]
2429
autocomplete_fields = ["choice", "poll", "user"]

0 commit comments

Comments
 (0)