django-seo icon indicating copy to clipboard operation
django-seo copied to clipboard

Flatpages per page SEO data editing

Open pythonpro opened this issue 12 years ago • 4 comments

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.

pythonpro avatar Apr 30 '12 13:04 pythonpro

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.

smcoll avatar Jul 30 '12 16:07 smcoll

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.

samzhao avatar Aug 15 '12 04:08 samzhao

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

smcoll avatar Aug 15 '12 14:08 smcoll

Thanks for your response!

samzhao avatar Aug 15 '12 14:08 samzhao