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

populate_from does not populate values #23

Open thedrow opened 13 years ago

thedrow commented 13 years ago

I have the following model:

from django.db import models
from rollyourown import seo
from autoslug import AutoSlugField
from django.core.urlresolvers import reverse
from tagging.fields import TagField

class Post(models.Model):
    slug = AutoSlugField(populate_from = 'title', unique = True)
    title = models.CharField(max_length = 200)
    content = models.TextField(blank = True)
    is_published = models.BooleanField(default = False)
    created_on = models.DateField(auto_now = True)
    published_on = models.DateField()
    tags = TagField()

    def get_absolute_url(self):
        return reverse('post', args = [self.slug])

    def __unicode__(self):
        return self.title

def populate_title(metadata, model_instance = None, **kwargs):
    print metadata
    if model_instance:
        return "Omer Katz - Personal Webstie | %s" % model_instance.title
    else:
        return '321'

def populate_description(metadata, model_instance = None, **kwargs):
    if model_instance:
        return model_instance.content
    else:
        return ''

def populate_keywords(metadata, model_instance = None, **kwargs):
    if model_instance:
        return model_instance.tags
    else:
        return ''

class PostMetadata(seo.Metadata):
    title = seo.Tag(head = True, max_length = 68, populate_from = populate_title)
    description = seo.MetaTag(max_length = 155, populate_from = populate_description)
    keywords = seo.KeywordTag(populate_from = populate_keywords)

    class Meta:
        seo_models = ('blog.Post',)
        verbose_name = "Post Metadata"
        verbose_name_plural = "Post Metadatas"

I can't figure out why the populate_from doesn't populate my metadata fields. Any idea?

nuno-iglesias commented 12 years ago

I'm also not sure of how to create automatic seo tags for my model instances.....