/ Published in: Django
example: a method on a model that outputs a list of tuples with (attribute_name.verbose, attribute_value)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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