When I describe admin options for a model it's possible to put any method in 'list_display' then we can add 'allow_tags=True' and get HTML. Is there any same options but for 'changeview' form? I can change template for the form but there is some calculation which returns HTML, so It's not good idea to put them all to a template.
class OrderAdmin(admin.ModelAdmin):
list_display = ('__unicode__','render_html')
render_html is a method of model, it works in listview, Putting it to 'fields' doesn't wo开发者_高级运维rk.
This is a hack but it should work.
class OrderAdmin(admin.ModelAdmin):
def render_change_form(self, request, context, *args, **kwargs):
context['adminform'].form.fields['somefield'].helptext= self.colored_name()
return super(OrderAdmin, self).render_change_form(request, context, args, kwargs)
def colored_name(self):
return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
colored_name.allow_tags = True
精彩评论