admin.py 1.58 KB
Newer Older
Arnaud Fabre's avatar
Arnaud Fabre committed
1
2
3
# coding: utf-8

from django.contrib import admin
4

5
from .models import Dossier, Document, Proposal, Vote
Arnaud Fabre's avatar
Arnaud Fabre committed
6
7
8


class DossierAdmin(admin.ModelAdmin):
9
    list_display = ('id', 'reference', 'title')
10
    search_fields = ('reference', 'title')
Arnaud Fabre's avatar
Arnaud Fabre committed
11
12


13
14
15
16
17
18
19
20
class DocumentAdmin(admin.ModelAdmin):
    list_display = ('dossier_reference', 'kind', 'title', 'link')
    search_fields = ('reference', 'dossier__reference', 'title')

    def dossier_reference(self, obj):
        return obj.dossier.reference


Arnaud Fabre's avatar
Arnaud Fabre committed
21
class ProposalAdmin(admin.ModelAdmin):
22
23
24
25
    list_display = (
        'reference',
        'dossier_reference',
        'title',
Jamesie Pic's avatar
Jamesie Pic committed
26
        'kind')
27
    search_fields = ('reference', 'dossier__reference', 'title')
28

Arnaud Fabre's avatar
Arnaud Fabre committed
29
30
31
32
33
    def dossier_reference(self, obj):
        return obj.dossier.reference


class NoneMatchingFilter(admin.SimpleListFilter):
34
35
    title = 'Representative'
    parameter_name = 'representative'
Arnaud Fabre's avatar
Arnaud Fabre committed
36
37
38

    def lookups(self, request, model_admin):
        return [('None', 'Unknown')]
39

Arnaud Fabre's avatar
Arnaud Fabre committed
40
41
    def queryset(self, request, queryset):
        if self.value() == 'None':
42
            return queryset.filter(representative=None)
Arnaud Fabre's avatar
Arnaud Fabre committed
43
        else:
44
            return queryset
Arnaud Fabre's avatar
Arnaud Fabre committed
45

46

Arnaud Fabre's avatar
Arnaud Fabre committed
47
class VoteAdmin(admin.ModelAdmin):
48
49
50
51
52
53
    list_display = (
        'id',
        'proposal_reference',
        'position',
        'representative',
        'representative_name')
Arnaud Fabre's avatar
Arnaud Fabre committed
54
    list_filter = (NoneMatchingFilter,)
55

Arnaud Fabre's avatar
Arnaud Fabre committed
56
57
58
    def proposal_reference(self, obj):
        return obj.proposal.reference

alexandre.jauneau's avatar
alexandre.jauneau committed
59

Arnaud Fabre's avatar
Arnaud Fabre committed
60
admin.site.register(Dossier, DossierAdmin)
61
admin.site.register(Document, DocumentAdmin)
Arnaud Fabre's avatar
Arnaud Fabre committed
62
63
admin.site.register(Proposal, ProposalAdmin)
admin.site.register(Vote, VoteAdmin)