summaryrefslogtreecommitdiff
path: root/postgresqleu/elections/admin.py
blob: f9b0c32868a0df439c0d26a823a69b98bd25f941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from django.contrib import admin
from django.forms import ValidationError, ModelForm

from models import Vote, Election, Candidate

class VoteAdminForm(ModelForm):
	class Meta:
		model = Vote
		exclude = []

	def clean(self):
		raise ValidationError("You really shouldn't edit votes! If you *really* need to fix something broken, do it in the db")

class VoteAdmin(admin.ModelAdmin):
	list_display = ('election', 'voter', 'candidate', 'score')
	ordering = ['election', ]
	form = VoteAdminForm


class ElectionAdmin(admin.ModelAdmin):
	list_display = ['name', 'startdate', 'enddate', ]
	ordering = ['-startdate', ]

class CandidateAdmin(admin.ModelAdmin):
	list_display = ['name', 'election', ]
	list_filter = ['election', ]
	ordering = ['name', ]

admin.site.register(Election, ElectionAdmin)
admin.site.register(Candidate, CandidateAdmin)
admin.site.register(Vote, VoteAdmin)