Skip to content

Commit 8754069

Browse files
committed
Enhance PollAdmin functionality with visibility controls
- Added a new fieldset for poll visibility in the admin interface. - Updated list display to include the 'is_private' status of polls. - Enhanced list filtering to allow filtering by poll visibility. - Introduced actions to mark selected polls as private or public, updating their visibility status accordingly.
1 parent ccbd978 commit 8754069

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

approval_polls/admin.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ class PollAdmin(admin.ModelAdmin):
6363
fieldsets = [
6464
(None, {"fields": ["question"]}),
6565
("Date information", {"fields": ["pub_date"], "classes": ["collapse"]}),
66+
("Visibility", {"fields": ["is_private"]}),
6667
]
6768
inlines = [ChoiceInline]
68-
list_display = ("id", "question", "pub_date")
69-
list_filter = ["pub_date"]
69+
list_display = ("id", "question", "pub_date", "is_private")
70+
list_filter = ["pub_date", "is_private"]
7071
search_fields = ["question"]
71-
actions = ["export_voters_as_csv"]
72+
actions = ["export_voters_as_csv", "make_private", "make_public"]
7273

7374
@admin.display(description="Export poll with opt-in voter emails.")
7475
def export_voters_as_csv(self, queryset):
@@ -107,5 +108,21 @@ def export_voters_as_csv(self, queryset):
107108

108109
return response
109110

111+
@admin.action(description="Mark selected polls as private (hide from front page)")
112+
def make_private(self, request, queryset):
113+
updated = queryset.update(is_private=True)
114+
self.message_user(
115+
request,
116+
f"{updated} poll(s) marked as private and hidden from front page.",
117+
)
118+
119+
@admin.action(description="Mark selected polls as public (show on front page)")
120+
def make_public(self, request, queryset):
121+
updated = queryset.update(is_private=False)
122+
self.message_user(
123+
request,
124+
f"{updated} poll(s) marked as public and shown on front page.",
125+
)
126+
110127

111128
admin.site.register(Ballot)

0 commit comments

Comments
 (0)