Add topic to objective admin view
This commit is contained in:
parent
02ddc4ecf4
commit
1352f68bae
|
|
@ -1,7 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from wagtail.core.models import Page
|
||||
|
||||
from objectives.models import ObjectiveGroup, Objective, ObjectiveProgressStatus
|
||||
|
||||
from books.models import Topic
|
||||
|
||||
@admin.register(ObjectiveGroup)
|
||||
class ObjectiveGroupAdmin(admin.ModelAdmin):
|
||||
|
|
@ -11,9 +12,31 @@ class ObjectiveGroupAdmin(admin.ModelAdmin):
|
|||
|
||||
@admin.register(Objective)
|
||||
class ObjectiveAdmin(admin.ModelAdmin):
|
||||
list_display = ('text', 'group', 'owner')
|
||||
list_display = ('text', 'get_topic', 'group', 'owner')
|
||||
list_filter = ('group', 'owner')
|
||||
|
||||
def get_topic(self, obj):
|
||||
try:
|
||||
page = Page.objects.get(pk=obj.group.module.page_ptr_id)
|
||||
except Page.DoesNotExist:
|
||||
return None
|
||||
|
||||
parent_path = str(page.path)[:-4]
|
||||
|
||||
try:
|
||||
parent = Page.objects.get(path=parent_path)
|
||||
except Page.DoesNotExist:
|
||||
return None
|
||||
|
||||
try:
|
||||
topic = Topic.objects.get(page_ptr_id=parent.id)
|
||||
except Topic.DoesNotExist:
|
||||
return None
|
||||
|
||||
return topic.title
|
||||
|
||||
get_topic.short_description = 'Thema'
|
||||
|
||||
|
||||
@admin.register(ObjectiveProgressStatus)
|
||||
class ObjectiveProgressStatusAdmin(admin.ModelAdmin):
|
||||
|
|
|
|||
Loading…
Reference in New Issue