Python/Django debugging: print model’s containing data

If you have the model instance(s) you can simply call:

model_queryset.all().values()

https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.values

For just the list of fields using the model class itself see Django: Get list of model fields?

or directly the documentation – for Django 1.10 there is a dedicated section on how to work with fields: https://docs.djangoproject.com/en/1.10/ref/models/meta/#retrieving-all-field-instances-of-a-model

Leave a Comment