willhardy / django-seo

Provides a set of tools for managing Search Engine Optimisation (SEO) for Django sites.
BSD 3-Clause "New" or "Revised" License
251 stars 117 forks source link

Flatpages per page SEO data editing #33

Open pythonpro opened 12 years ago

pythonpro commented 12 years ago

Pls, clarify (here or in docs) how to add SEO fields inline to Flatpage creation/editing page without flatpages app admin.py file monkeypatching. Thnx.

smcoll commented 12 years ago

You're going to have to unregister the FlatPage from the admin site, and re-register your own ModelAdmin, configured for integration with this app.

What i tend to do is import a custom admin overrides module immediately following the admin.autodiscover() in my project's urls.py:

admin.autodiscover()
# import admin overrides
import myproject.admin

The myproject/admin.py file looks something like this:

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

from rollyourown.seo.admin import get_inline
from myproject.myapp.seo import Metadata # your custom metadata model

class CustomFlatPageAdmin(FlatPageAdmin):
    inlines = [get_inline(Metadata)]

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, CustomFlatPageAdmin)

While you're at it, use CustomFlatPage admin to make all those FlatPage ModelAdmin modifications you always wanted to do.

samzhao commented 12 years ago

Thank you, smcoll, for your helpful comment. I'm trying to do the exact same thing as what pythonpro is trying to do. I think I understand what you are suggesting in your comment, but could you provide more details on how to actually write the rollyourown.seo.admin model and the myproject.myapp.seo model? I'm a Django noob, so I don't know exactly how to write those models. I do understand how this whole works in theory, though.

Thanks.

smcoll commented 12 years ago

The rollyourown.seo.admin module is part of the django-seo package- you don't have to write it.

See the Django SEO docs for help in constructing the metadata model:

http://django-seo.readthedocs.org/en/latest/introduction/tutorial.html#metadata-definition http://django-seo.readthedocs.org/en/latest/reference/definition.html#reference-definition

samzhao commented 12 years ago

Thanks for your response!