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

Model instance admin #1

Closed klichukb closed 13 years ago

klichukb commented 13 years ago

Hi, willhardy. Thank you for such a great framework. I have a question related to admin representation of seo model for the model instances: why are the fields "_content_type" and "_object_id" not editable? They are not visible in the admin. How am i supposed then to add an instance of SEO model for a particular object?

Please, clearify this to me if i didn't notice something.

By the way, Django 1.2.1, Python 2.6

willhardy commented 13 years ago

If you register a model as being an "SEO model", it should automatically create SEO model instance for each of your model instances. To register a model, use the seo_models meta option, and provide of list of app names or even specific models. For example:

   class BasicExample(seo.MetaData):
       heading = seo.Tag(name="h1")

       class Meta:
           seo_models = ('myapp', 'flatpages.FlatPage')

I'll close this ticket, but please reopen if you think that it should be possible to manually add seo models in the admin for a given model instance. It wouldn't be too difficult to implement, but I prefer to keep things simple.

klichukb commented 13 years ago

Thank you for your response. The problem i had was not knowing that the proper way to add a metadata instance for a model instance is inlines, placed on the model instance's admin. Because these fields "_content_type_id" and "_object_id" are not visible in a usual form.

I have a situation, where i need to place inlines for inlines. That is, objects, which should have metadata in inline, are inlines itself (don't have a normal admin). Trying now to implement something like "Add another" button (in front of related fields in Django admin forms) to open a popup for creating a metadata instance in that popup for a specified inline object. Maybe you can probably advice something? Because, i think, that is somewhere too complex, and it has to be simplier. Thank you one more.

willhardy commented 13 years ago

I'm not sure if there is anything currently in this library that will solve your problem directly. I've added documentation to readthedocs.org, which might be helpful.

philippWassibauer commented 13 years ago

I can't get the inlines to work. Once I register it and go to the Model in the Admin I get the error: MyMetadataModelInstance has no field named 'content_type'

from app.seo import MyMetadata

class ProfileAdmin(admin.ModelAdmin): inlines = [get_inline(MyMetadata)]

admin.site.register(Profile, ProfileAdmin)


In the seo.py I have:

from rollyourown import seo

class MyMetadata(seo.Metadata): title = seo.Tag(head=True, max_length=68) description = seo.MetaTag(max_length=155) keywords = seo.KeywordTag() class Meta: seo_models = ('event.Event', 'profiles.Profile', 'blog.Post')

Am I doing something wrong or is this a bug?

Thanks, Phil

willhardy commented 13 years ago

This sounds like a bug, the field should be called _content_type (the underscore is to allow you to add your own metadata field called content_type).

I suspect the following fields are missing from the inline created for you:

ct_field = "_content_type"
ct_fk_field = "_object_id"

I'll try to create a test to catch this and add the two fields to the inline.

willhardy commented 13 years ago

I've committed an automated test and a fix for this problem. Thanks for letting me know!