Skip to content

Commit

Permalink
Addressing #3 and #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbeattie committed Apr 15, 2017
1 parent 287b9bf commit 759bd38
Show file tree
Hide file tree
Showing 27 changed files with 276 additions and 8,781 deletions.
46 changes: 23 additions & 23 deletions elections/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ def show_links(self, obj):


class SessionAdmin(HasLinks, CommonAdmin):
list_display = ("pk", "parliament", "number", "date_start", "date_end", "show_links")
list_display = ("parliament", "number", "date_start", "date_end", "show_links")
list_filter = ("parliament", )
admin.site.register(models.Session, SessionAdmin)


class ProvinceAdmin(HasNameVariants, CommonAdmin):
list_display = ("pk", "name", "show_name_variants", "elections")
list_filter = ("ridings__election_ridings__election", )
class ProvinceAdmin(HasNameVariants, HasLinks, CommonAdmin):
list_display = ("name", "show_name_variants", "elections", "show_links")
list_filter = ("ridings__election_ridings__general_election", )

def elections(self, obj):
return ", ".join(map(
lambda x: str(x),
sorted(
models.Election.objects.filter(
models.GeneralElection.objects.filter(
election_ridings__riding__province=obj,
).distinct().values_list("number", flat=True)
)
Expand All @@ -48,12 +48,12 @@ def elections(self, obj):


class ElectionAdmin(HasLinks, CommonAdmin):
list_display = ("pk", "number", "date_end", "show_links", "population", "registered", "ballots_total", "turnout")
admin.site.register(models.Election, ElectionAdmin)
list_display = ("number", "date_end", "show_links", "population", "registered", "ballots_total", "turnout")
admin.site.register(models.GeneralElection, ElectionAdmin)


class ParliamentAdmin(HasLinks, CommonAdmin):
list_display = ("pk", "number", "government_party", "color_swatch", "show_links")
list_display = ("number", "government_party", "color_swatch", "show_links")

def color_swatch(self, obj):
if obj.government_party:
Expand All @@ -62,15 +62,15 @@ def color_swatch(self, obj):


class PartyAdmin(HasNameVariants, HasLinks, CommonAdmin):
list_display = ("pk", "name", "color_swatch", "show_name_variants", "show_links", "elections")
list_filter = ("election_candidates__election_riding__election", )
list_display = ("name", "color_swatch", "show_name_variants", "show_links", "elections")
list_filter = ("election_candidates__election_riding__general_election", )
search_fields = ("name", "name_variants")

def elections(self, obj):
return ", ".join(map(
lambda x: str(x),
sorted(
models.Election.objects.filter(
models.GeneralElection.objects.filter(
election_ridings__election_candidates__party=obj,
).distinct().values_list("number", flat=True)
)
Expand All @@ -79,8 +79,8 @@ def elections(self, obj):


class PersonAdmin(HasNameVariants, HasLinks, CommonAdmin):
list_display = ("pk", "name", "show_name_variants", "show_links", "elections", "show_photo")
list_filter = ("election_candidates__election_riding__election", )
list_display = ("name", "show_name_variants", "show_links", "elections", "show_photo")
list_filter = ("election_candidates__election_riding__general_election", )
search_fields = ("name", )

def show_photo(self, obj):
Expand All @@ -91,7 +91,7 @@ def elections(self, obj):
return ", ".join(map(
lambda x: str(x),
sorted(
models.Election.objects.filter(
models.GeneralElection.objects.filter(
election_ridings__election_candidates__person=obj,
).distinct().values_list("number", flat=True)
)
Expand All @@ -100,15 +100,15 @@ def elections(self, obj):


class RidingAdmin(HasNameVariants, HasLinks, CommonAdmin):
list_display = ("pk", "province", "name", "show_name_variants", "show_links", "elections")
list_display = ("name", "province", "show_name_variants", "show_links", "elections")
search_fields = ("name", )
list_filter = ("province", "election_ridings__election")
list_filter = ("province", "election_ridings__general_election")

def elections(self, obj):
return ", ".join(map(
lambda x: str(x),
sorted(
models.Election.objects.filter(
models.GeneralElection.objects.filter(
election_ridings__riding=obj,
).distinct().values_list("number", flat=True)
)
Expand All @@ -117,17 +117,17 @@ def elections(self, obj):


class ElectionRidingAdmin(HasLinks, CommonAdmin):
list_display = ("pk", "election", "riding", "show_links", "population", "registered")
search_fields = ("election__number", "riding__name")
list_filter = ("election", "riding__province")
list_display = ("riding", "general_election", "show_links", "population", "registered")
search_fields = ("general_election__number", "riding__name")
list_filter = ("general_election", "riding__province")
admin.site.register(models.ElectionRiding, ElectionRidingAdmin)


class ElectionCandidateAdmin(CommonAdmin):
raw_id_fields = ("election_riding", "person")
list_display = ("pk", "election_riding", "person", "party", "color_swatch", "profession", "ballots", "ballots_percentage", "elected", "acclaimed", "show_photo")
list_filter = ("elected", "acclaimed", "election_riding__election", "election_riding__riding__province")
search_fields = ("election_riding__election__number", "election_riding__riding__name", "person__name", "party__name", "party__name_variants")
list_display = ("person", "election_riding", "party", "color_swatch", "profession", "ballots", "ballots_percentage", "elected", "acclaimed", "show_photo")
list_filter = ("elected", "acclaimed", "election_riding__general_election", "election_riding__riding__province")
search_fields = ("election_riding__general_election__number", "election_riding__riding__name", "person__name", "party__name", "party__name_variants")

def show_photo(self, obj):
if obj.person.photo:
Expand Down
Loading

0 comments on commit 759bd38

Please sign in to comment.