I want to iterate through User
model and the UserProfile
model that is attached to User
to display all the information about the User in a profile page such as
UserName:
FirstName:
LastName:
Date of Birth:
.....
Is there a generic templateView, that I can use to pass the model and gets its fields displayed on template. Reading many SO articles, I tried this:
##display user fields
{% for field in User._meta.get_all_field_names() %}
<p> {{ field }} : {{ getatttr(field,user) }} </p>
{% endfor %}
## display Userprofile fields
{for field in User.profile._meta.get_all_field_names() %}
<p> {{ field }} : {{ getatttr(field,user.profile) }} </p>
{% endfor %}
This does not work: in fact, I tried only to display all the fields and not its values first:
{% for field in User._meta.get_all_field_names() %}
<p> {{ field }} </p>
{% endfor %}
but I get this error: Variables and attributes may not begin with underscores: 'User._meta.get_all_field_names'
Any idea how to fix this?
{{ field }} : {{ value|yesno:"-----" }}
{% endfor %}` but it is not displaying yes/no. why is that? – eagertoLearn Mar 27 '14 at 19:35