我404
在尝试发帖时遇到错误。但错误是event objects don't have get_absolute_url() methods
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
我如何正确地完成这项工作?感谢您提前提供帮助。