作者Lucemia (生の直感、死の予感)
看板Python
标题[问题] django 的小问题
时间Wed Nov 21 07:44:42 2007
自解:
Trace code後找出毛病来了
原来少打了一行.. = =
class Person(models.Model):
first_name = models.CharField(max_length=50)
color_code = models.CharField(max_length=6)
class Admin:
list_display = ('first_name', 'colored_first_name')
def colored_first_name(self):
return '<span style="color: #%s;">%s</span>' %
(self.color_code, self.first_name)
colored_first_name.admin_order_field = 'first_name'
colored_first_name.allow_tags = True ## need this line
======================================================
请教一个问题
http://www.djangoproject.com/documentation/model-api/#admin-options
class Person(models.Model):
first_name = models.CharField(max_length=50)
color_code = models.CharField(max_length=6)
class Admin:
list_display = ('first_name', 'colored_first_name')
def colored_first_name(self):
return '<span style="color: #%s;">%s</span>' %
(self.color_code, self.first_name)
colored_first_name.allow_tags = True
colored_first_name.admin_order_field = 'first_name'
里头有段程式码长这样
用意是在 list display 的地方让
使用html 让 colored_first_name 这栏有颜色
嗯.. 我试的结果却是 colored_first_name 这栏直接变成
这串字串了 "<span style ....></span>"
这是怎样 =__=?
目前用的是 django 0.96 development version
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.110.216.36
※ 编辑: Lucemia 来自: 140.110.216.36 (11/22 01:46)
※ 编辑: Lucemia 来自: 140.110.216.36 (11/22 01:48)