嘗試發佈時,出現404
錯誤。但錯誤是event objects don't have get_absolute_url() methods
創建get_absolute_url()
class Event(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
date = models.DateTimeField()
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
avatar = models.ImageField(upload_to='avatars/events/', null=True, blank=True)
tags = models.ManyToManyField(Tag, null=True, blank=True)
class Meta:
ordering = ['-date']
def __unicode__(self):
return self.title
# I made this, but this doesn't work
def get_absolute_url(self):
return "/event/" + self.id
# it returns :
Exception Type: TypeError
Exception Value: cannot concatenate 'str' and 'int' objects
我該如何正確地完成這項工作?感謝您提前幫忙。
你能發佈與該模型相關的urls.py文件嗎? – 2012-07-30 20:59:38