Revision: 21850
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 22, 2009 15:17 by magicrebirth
Initial Code
def attrs_verbose(self):
model = self.__class__
# using this form: Record._meta.get_field('created_by').verbose_name
items = []
for k, v in self.__dict__.items():
try:
x = model._meta.get_field(k).verbose_name
except:
x = k
items += [(x, v)]
items.sort()
return items
Initial URL
Initial Description
example: a method on a model that outputs a list of tuples with (attribute_name.verbose, attribute_value)
Initial Title
Django: access the attributes of a model dynamically
Initial Tags
django
Initial Language
Django