views:

217

answers:

1

In my flatpage admin change list page, mysite.com/admin/flatpages/flatpage/, I can see the fields:

  1. URL
  2. Title

Is there a way to also show the field Site? I associate my flatpages to specific sites. The bad way to do it is by going to the actual Flatpage admin source django/contrib/flatpages/admin.py and create a method which will display sites for a Flatpage on the change list page.

I am basically looking for a way to overwrite a django.contrib application on the admin side.

+4  A: 

You don't need to edit flatpages/admin.py. Instead, create a CustomFlatPageAdmin that inherits from the default FlatPageAdmin.

You might want to create a customflatpage app for the following admin.py file, or perhaps you already have a utilities app that you can add it to.

#admin.py
from django.contrib import admin

from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin

def get_sites(obj):
    'returns a list of site names for a FlatPage object'
    return ", ".join((site.name for site in obj.sites.all()))
get_sites.short_description = 'Sites'

class CustomFlatPageAdmin(FlatPageAdmin):
    list_display = ('title', 'url', get_sites)

#unregister the default FlatPage admin and register CustomFlatPageAdmin.
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, CustomFlatPageAdmin)
Alasdair