I'm trying to make a registration form for a extension of django's user model. It has a two relationships, one to User and Address. The form needs to have all the fields from User, UserDetails and Address. But i'm struggling to get the correct view and form. Just having a ModelForm for UserDetails combined with FormView doesn't add the fields for User and Address.
class User(AbstractBaseUser, PermissionMixin):
email = models.EmailField(unique=True)
class UserDetails(model.Model):
date_of_birth = models.DateField()
user = models.ForeignKey(User, on_delete=models.CASCADE)
address = models.OneToOneField(Address, on_delete=models.CASCADE)
class Address(model.Model):
field = models.CharField(max_length=100)
field2 = models.CharField(max_length=100)
The form and view look like this:
class UserRegistrationForm(ModelForm):
class Meta:
model = Orchestra
fields = '__all__'
class UserRegistrationView(FormView):
form_class = UserRegistrationForm
template_name = 'users/register.html'
<form action="" method="post">
{% csrf_token %}
{{ form.as_table }}
<input type="submit" value="submit">
</form>