Thanks for both you help!
I tried the suggested approach to see where it gets me and read the links provided.
The suggested MemberCreateForm seems to work, I have the new field in the form and when submitting, it is saved!
But there is a new error after submitting the form:
AttributeError at /accounts/signup/
Exception Value: 'NoneType' object has no attribute '__dict__'
Exception Location: /usr/local/lib/python3.9/site-packages/django/views/generic/edit.py, line 113, in get_success_url
Now I am confused why there seems to be a problem with the success_url that I have not changed.
I am also not sure if the save function replaces the init function, but adding to the MemberCreateForm class (in forms.py) seems not make it better (or worse).
class MemberCreateForm(UserCreationForm):
pin = forms.CharField(max_length=100)
class Meta:
fields = ("username", "email", "password1", "password2", "pin")
model = get_user_model()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def save(self, *args, **kwargs):
# Let the UserCreationForm handle the user creation
username = super().save(*args, **kwargs)
# With the user create a Member
Member.objects.create(user=username, pin=self.cleaned_data.get("pin"))
Do I understand correctly, that this would not be the recommended way and I should avoid using class based views to do this?
I guess I need “Multiple separate models that are related, and one submit button saves all”,
because I want a user that registers to provide the additional value “pin” at the registration form and have the value stored related to their a user account
instead of extending the default django user model.
And so I guess should “use the formset facility with the formset having a limit of 1 form, and not providing any facility to add forms”, but I don’t understand this yet