2

I have a form that is based on the model User from django.contrib.auth.models

I have created another model called UserProfile which contains more information about the user.

In my forms.py I have a form that is based on:

class Meta:
    model = User

How can I show in my html the fields that is owned by UserProfile class?

PS.: In UserProfile class I have already created a field user = models.OneToOneField(User)

Thanks in advance!

Lucas Rezende
  • 2,516
  • 8
  • 25
  • 34
  • possible duplicate of [Muliple Models in a single django ModelForm?](http://stackoverflow.com/questions/2770810/muliple-models-in-a-single-django-modelform) – Alasdair Jun 13 '12 at 19:26

2 Answers2

3

Create two forms and display them both in the same <form> tag. Then manually check whether the forms are valid and call form.save() on both of them. It's a bit more work but perhaps cleaner than merging them forcefully into one form.

(credit)

Community
  • 1
  • 1
Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
0

Essentially what you need to look at is in-line forms. They cover it well for admin customization but the same principle applies when using ModelForms. Usually people just sub-class User?

eusid
  • 769
  • 2
  • 6
  • 18