Skip to content

Instantly share code, notes, and snippets.

@alxscms
Created January 5, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alxscms/9aa81fa53bcf4018bc62 to your computer and use it in GitHub Desktop.
Save alxscms/9aa81fa53bcf4018bc62 to your computer and use it in GitHub Desktop.
Print all attributes of a django model with colors
def print_model(object):
print "\033[96m<{0}>\033[0m".format(wp.__class__.__name__)
for field in object._meta.fields:
if field.value_to_string(object) != 'None' and field.value_to_string(object) != '':
print "\033[94m{0:30}\033[0m \033[93m{1}\033[0m".format(field.name, field.value_to_string(object))
else:
print "{0:30} {1}".format(field.name, field.value_to_string(object))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment