Iterate over model instance field names and values in template

model._meta.get_all_field_names() will give you all the model’s field names, then you can use model._meta.get_field() to work your way to the verbose name, and getattr(model_instance, 'field_name') to get the value from the model.

NOTE: model._meta.get_all_field_names() is deprecated in django 1.9. Instead use model._meta.get_fields() to get the model’s fields and field.name to get each field name.

Leave a Comment