summaryrefslogtreecommitdiff
path: root/postgresqleu/elections/admin.py
blob: b29db362cfdfbec14e005082d638958cdcdd8641 (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
32
33
34
35
36
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')
    autocomplete_fields = ('voter', )
    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)