def contribute_to_class(self, cls, name, **kwargs):
"""
Adds a @property: «name»_str that returns a string representation of
the attributes ready for inclusion on an HTML element.
"""
super(AttributesField, self).contribute_to_class(cls, name, **kwargs)
# Make sure we're not going to clobber something that already exists.
property_name = '{name}_str'.format(name=name)
if not hasattr(cls, property_name):
str_property = curry(self.to_str, field_name=name)
setattr(cls, property_name, property(str_property))
评论列表
文章目录