I'm trying to set title_for_url
but it shows up in my database as "<property object at 0x027427E0>
". What am I doing wrong?
from django.db import models
class Entry(models.Model):
def _get_title_for_url(self):
title = "%s" % self.get_title_in_url_format()
return title
AUTHOR_CHOICES = (('001', 'John Doe'),)
post_date = models.DateField()
author = models.CharField(max_length=3, choices=AUTHOR_CHOICES)
title = models.CharField(max_length=100, unique=True)
body = models.TextField()
image = models.ImageField(upload_to='image/blog')
image.blank = 'true'
title_for_url = models.CharField(max_length=100, editable=False, default=property(_get_title_for_url))
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/blog/%s/" % self.get_title_in_url_format()
def get_title_in_url_format(self):
"Returns the title as it will be displayed as a URL, stripped of special characters with spaces replaced by '-'."
import re
pattern = re.compile( '(\'|\(|\)|,)' )
titleForUrl = pattern.sub('', self.title)
pattern = re.compile( '( )' )
titleForUrl = pattern.sub('-', titleForUrl)
return titleForUrl.lower()