Commit 91c753d5 authored by justin's avatar justin

Fixed admin.py logic

parent f249f755
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction from .models import Announcement, Reaction
# Register your models here.
# show reactions in page for announcements # show reactions in page for announcements
class ReactionInline(admin.TabularInline): class ReactionInline(admin.TabularInline):
model = Reaction model = Reaction
# announcement admin panel # announcement admin panel
class AnnouncementAdmin(admin.ModelAdmin): class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement model = Announcement
...@@ -18,7 +18,7 @@ class AnnouncementAdmin(admin.ModelAdmin): ...@@ -18,7 +18,7 @@ class AnnouncementAdmin(admin.ModelAdmin):
search_fields = ("title", "body") search_fields = ("title", "body")
# filter by author # filter by author
list_filter = ("get_author") list_filter = ("author",)
def get_author(self, obj): def get_author(self, obj):
return obj.author.displayName() return obj.author.displayName()
...@@ -28,25 +28,27 @@ class AnnouncementAdmin(admin.ModelAdmin): ...@@ -28,25 +28,27 @@ class AnnouncementAdmin(admin.ModelAdmin):
inlines = [ReactionInline] inlines = [ReactionInline]
class ReactionAdmin(admin.ModelAdmin): class ReactionAdmin(admin.ModelAdmin):
# display reaction name, tally, announcement # display reaction name, tally, announcement
list_display = ("reaction_name", "tally", "get_name") list_display = ("name", "tally", "announcement")
# search by announcement name # search by announcement name
search_fields = ("get_name") search_fields = ("name",)
# filter by announcement # filter by announcement
list_filter = ("get_name") list_filter = ("announcement__title",)
#
def get_name(self, obj): # def get_name(self, obj):
return obj.announcement.title # return obj.announcement.title
#
# title of column for get_name # # title of column for get_name
get_name.short_description = "Announcement Title" # 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(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin) 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