Commit 91c753d5 authored by justin's avatar justin

Fixed admin.py logic

parent f249f755
from django.contrib import admin
from .models import Announcement, Reaction
# Register your models here.
# show reactions in page for announcements
class ReactionInline(admin.TabularInline):
model = Reaction
# announcement admin panel
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
......@@ -18,7 +18,7 @@ class AnnouncementAdmin(admin.ModelAdmin):
search_fields = ("title", "body")
# filter by author
list_filter = ("get_author")
list_filter = ("author",)
def get_author(self, obj):
return obj.author.displayName()
......@@ -28,25 +28,27 @@ class AnnouncementAdmin(admin.ModelAdmin):
inlines = [ReactionInline]
class ReactionAdmin(admin.ModelAdmin):
# display reaction name, tally, announcement
list_display = ("reaction_name", "tally", "get_name")
list_display = ("name", "tally", "announcement")
# search by announcement name
search_fields = ("get_name")
search_fields = ("name",)
# filter by announcement
list_filter = ("get_name")
def get_name(self, obj):
return obj.announcement.title
# title of column for get_name
get_name.short_description = "Announcement Title"
list_filter = ("announcement__title",)
#
# def get_name(self, obj):
# return obj.announcement.title
#
# # title of column for get_name
# get_name.short_description = "Announcement Title"
#
# # sorting by announcement
# get_name.admin_order_field = "announcement"
# sorting by announcement
get_name.admin_order_field = "announcement"
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment