After creating the member record in the application, only the username is reflected in the admin panel, but I want to get the name and surname as well. I specify this in the codes, but there is no reflection.
views.py
from django.shortcuts import render,redirect
from .forms import RegisterForm
from django.contrib.auth.models import User
from django.contrib.auth import login
from django.contrib import messages
def register(request):
form=RegisterForm(request.POST or None)
if form.is_valid():
name=form.cleaned_data.get("name")
lastname=form.cleaned_data.get("lastname")
username=form.cleaned_data.get("username")
password=form.cleaned_data.get("password")
#newUser=User(name=name)
newUser = User(username=username)
newUser.set_password(password)
newUser.save()
login(request,newUser)
messages.info(request,"Başarıyla Kayıt Oldunuz...")
return redirect("index")
context={
"form":form
}
return render(request,"register.html",context)
Form.py
from django import forms
from django.contrib.auth.forms import UserCreationForm
class RegisterForm(forms.Form):
name=forms.CharField(max_length=50,label="Adı ")
lastname=forms.CharField(max_length=50,label="Soyadı ")
username=forms.CharField(max_length=50,label="Kullanıcı Adı ")
password=forms.CharField(max_length=20,label="Parola",widget=forms.PasswordInput)
confirm=forms.CharField(max_length=20,label="Parolayı Doğrula ",widget=forms.PasswordInput)
def clean(self):
name=self.cleaned_data.get("name")
lastname=self.cleaned_data.get("lastname")
username=self.cleaned_data.get("username")
password=self.cleaned_data.get("password")
confirm=self.cleaned_data.get("confirm")
if password and confirm and password != confirm:
raise forms.ValidationError("Parolalar Eşleşmiyor...")
values = {
"name" : name,
"lastname" :lastname,
"username" : username,
"password" : password,
}
return values
Although I specify the name and name fields, it is not reflected in the panel
import user in form.py
from django.contrib.auth.models import User
pass the following below class Register form
class Meta:
model= User
fields=['']```
newUser = User(username=username, firstname=name, lastname=lastname)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.