I have extended Django's user model with a Profile model:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
date_of_birth = models.DateField()
address = models.CharField(max_length=300)
postcode = models.CharField(max_length=15)
Then, I pass this data into a template via this view:
def profile(request):
args = {'user': request.user}
return render(request, 'users/profile.html', args)
Then I can access each field of the Profile model individually in the template with:
<p>Your DOB is: {{ user.profile.date_of_birth }}</p>
However, I want to use a for loop to say:
{%for field in Profile model %}
<p>{{field name}} = {{field value}}
{% endfor %}
But I've tried a lot of different things, none of them work, e.g.
{% for field in user.profile.all %}
<p>{{ field }}</p>
{% endfor %}
(This compiles but is blank when the template is ran)