Hi, now I try to extend the user model of my django app to store a pin and a balance with the useraccount when the new user registers.
My models.py looks like this:
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
# Create your models here.
class Member(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
pin = models.CharField(max_length=100)
balance = models.IntegerField()
def __str__(self):
return "@{}".format(self.user.name)
now I try extending the registration form at forms.py
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.forms import forms
from accounts.models import Member
class MemberCreateForm(UserCreationForm):
class Meta:
fields = ("username", "email", "password1", "password2", "pin")
model = get_user_model()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["username"].label = "Name"
self.fields["email"].label = "email"
self.fields["pin"].label = "pin"
and call it from the views.py
from django.urls import reverse_lazy
from django.views.generic import CreateView
from . import forms
# Create your views here.
class SignUp(CreateView):
form_class = forms.MemberCreateForm
success_url = reverse_lazy("accounts:login")
template_name = "accounts/signup.html"
but
django.core.exceptions.FieldError: Unknown field(s) (pin) specified for User
I found this in the docs and this on stackoverflow, but I am lost…