get_absolute_url

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Sample(models.Model):
name = models.CharField(max_length=30)
def get_absolute_url(self):
return "http://muzx.servehttp.com/p/%d/" % self.id
###################################################################
#template
{% for i in lam %}
{{ i.get_absolute_url }} {{ i.name }}<br />
{% endfor %}