I have a model which includes user object, and an extended form based on this model.
How do I access the User object’s fields in the form? If this is not the way to do it, what is a recommended way?
models.py
class Driver(models.Model):
user = models.OneToOneField(User)
phone = models.CharField(max_length=200)
mobile = models.CharField(max_length=200)
forms.py
class DriverRegistrationForm(ModelForm):
class Meta:
model = Driver
page.html (What I would have liked to do…)
<label for="id_username">Username<span class="small">Add your name</span></label>{{form.user.username}}<!-- Not like this... -->
<label for="id_password">Password <span class="small">Small and big letters</span></label>{{form.user.password}}<!-- Not like this... -->
<label for="id_phone">Phone <span class="small">Your phone number</span></label>{{form.phone}}
In this case you can also extend the default user creation form