简体   繁体   English

Django 在管理面板中查看所有用户信息

[英]Django see all user information in admin panel

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视图.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表格.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在 form.py 中导入用户

from django.contrib.auth.models import User

pass the following below class Register form通过下面的 class 注册表单

class Meta:
         model= User
         fields=['']```

newUser = User(username=username, firstname=name, lastname=lastname)  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM