You can push this code to your view, and use the handy django.forms.models.model_to_dict
function to get a dictionary of fields to values for user
and user.profile
views.py:
from django.forms.models import model_to_dict
class UserDetailView(DetailView):
model = User
def get_context_data(self, **kwargs):
context = super(UserDetailView, self).get_context_data(**kwargs)
context['user_attr_map'] = model_to_dict(self.object)
context['userprofile_attr_map'] = model_to_dict(self.object.profile)
return context
template.html:
{% for k, v in user_attr_map.items %}
<p> {{ k }} : {{ v }} </p>
{% endfor %}
{% for k, v in userprofile_attr_map.items %}
<p> {{ k }} : {{ v }} </p>
{% endfor %}