5

I'm using Django 1.4. I have two types of objects: Parts and Chapters. Parts have many Chapters via a foreign key. In the admin page of a Part object, I wanted to see a list of the Chapters that 'belong' to that part. So I did this:

from django.contrib import admin
from americano.apps.courses.models import Part, Chapter


class ChapterInline(admin.TabularInline):
    model = Chapter
    exclude = ['body', 'pub_date']
    readonly_fields = ('name', 'name_extension', 'number', 'lang')
    extra = 0


class PartAdmin(admin.ModelAdmin):
    list_display = ('name', 'number')
    search_fields = ['name']
    ordering = ['number']
    inlines = [ChapterInline]


class ChapterAdmin(admin.ModelAdmin):
    list_display = ('name', 'number', 'part', 'pub_date')
    list_display_links = ('name', 'part')
    ordering = ['number']
    search_fields = ['name']


admin.site.register(Part, PartAdmin)
admin.site.register(Chapter, ChapterAdmin)

What I would like now is to make the Chapters listed in the Part admin page clickable. I'd like them to link to the Chapter page. I tried to use list_display_links = ('name',) in the ChapterInline class, but it doesn't work. Does anyone have an idea? Thanks.

user1011444
  • 1,389
  • 2
  • 15
  • 25

0 Answers0