Mercurial > public > sg101
diff contests/admin.py @ 796:5977b43499f7
Modified contests to have multiple winners.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 04 Jul 2014 20:30:14 -0500 |
parents | ee87ea74d46b |
children |
line wrap: on
line diff
--- a/contests/admin.py Fri Jun 06 18:28:28 2014 -0500 +++ b/contests/admin.py Fri Jul 04 20:30:14 2014 -0500 @@ -10,13 +10,13 @@ class ContestAdmin(admin.ModelAdmin): list_display = ['title', 'is_public', 'creation_date', 'end_date', - 'contestant_count', 'winner'] + 'contestant_count', 'winner_count'] list_editable = ['is_public'] date_hierarchy = 'creation_date' search_fields = ['title', 'description'] prepopulated_fields = {'slug': ['title']} - raw_id_fields = ['winner', 'contestants'] - actions = ['pick_winner'] + raw_id_fields = ['contestants', 'winners'] + actions = ['pick_winners'] class Media: js = (['js/contests/contests_admin.js'] + @@ -26,7 +26,11 @@ return obj.contestants.count() contestant_count.short_description = '# Entries' - def pick_winner(self, request, qs): + def winner_count(self, obj): + return obj.winners.count() + winner_count.short_description = '# Winners' + + def pick_winners(self, request, qs): """ Picks a winner on the contests selected by the admin. Note that for safety reasons, we only update those contests that don't have winners @@ -35,15 +39,15 @@ """ count = 0 for contest in qs: - if not contest.winner: - contest.pick_winner() + if not contest.win_date: + contest.pick_winners() contest.save() count += 1 self.message_user(request, "%d of %d winners picked" % (count, qs.count())) - pick_winner.short_description = "Pick winners for selected contests" + pick_winners.short_description = "Pick winners for selected contests"