19 views
Skip to first unread message

郑 玉婷

unread,
May 9, 2022, 9:18:46 AM5/9/22
to django...@googlegroups.com

Dear django workers,

       First of all ,I have to appoloy for my poor English.

I want to add users through admin page ,which was registed by my own model . How can I add users with encoding their password?

These are my models and my admin.py. Ill be grateful if you can help me

 

#mysite\login\admin.py

from os import read

from django.contrib import admin

from django.contrib.auth.admin import UserAdmin

from . import models

from login import views

# Register your models here.

 

admin.site.register(models.Manager)

admin.site.register(models.Student)

admin.site.register(models.Teacher)

admin.site.site_header = '真人图书馆管理后台'  # 设置header

admin.site.site_title = '真人图书馆管理后台'   # 设置title

admin.site.index_title = '真人图书馆主页'

 

#mysite\login\models.py

from distutils.command.upload import upload

from importlib.resources import path

from django.db import models

 

# Create your models here.

 

class Student(models.Model):

 

    gender = (

        ('male', ""),

        ('female', ""),

    )

 

    name = models.CharField(max_length=128, unique=True)

    password = models.CharField(max_length=256)

    email = models.EmailField(unique=True)

    sex = models.CharField(max_length=32, choices=gender, default="")

    c_time = models.DateTimeField(auto_now_add=True)

 

    def __str__(self):

        return self.name

 

    class Meta:

        ordering = ["-c_time"]

        verbose_name = "学生"

        verbose_name_plural = "学生"

 

class Manager(models.Model):

 

    name = models.CharField(max_length=128, unique=True)

    password = models.CharField(max_length=256)

    email = models.EmailField(unique=True)

    c_time = models.DateTimeField(auto_now_add=True)

 

    def __str__(self):

        return self.name

 

    class Meta:

       ordering = ["-c_time"]

        verbose_name = "管理员"

        verbose_name_plural = "管理员"

 

class Teacher(models.Model):

 

    gender = (

        ('male', ""),

        ('female', ""),

    )

 

    name = models.CharField(max_length=128, unique=True)

    password = models.CharField(max_length=256)

    sex = models.CharField(max_length=31, choices=gender, default="")

    image = models.ImageField(default = "",upload_to= 'media/')   

    email = models.EmailField(unique=True)

    telephone = models.CharField(max_length = 11)

    subject = models.CharField(max_length=20)

    c_time = models.DateTimeField(auto_now_add=True)

 

    def __str__(self):

        return self.name

 

    class Meta:

        ordering = ["-c_time"]

        verbose_name = "老师"

        verbose_name_plural = "老师"

                                                          Best wishes!

                                     Molly

 

 

 

郑 玉婷

unread,
May 9, 2022, 9:18:47 AM5/9/22
to django...@googlegroups.com

Dear django workers,

       First of all ,I have to appoloy for my poor English.

I want to add users through admin page ,which was registed by my own model . How can I add users with encoding their password?

These are my models and my admin.py. Ill be grateful if you can help me

                                                          Best wishes!

                                     Molly

 

 

Muhammad Juwaini Abdul Rahman

unread,
May 10, 2022, 12:10:36 AM5/10/22
to django...@googlegroups.com
I think it's better for you to inherit from 'User' model instead of creating them one by one.

'User' model have column 'name', 'password', 'email' (among others) etc.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ME3P282MB1682636F0E189716B7A32546D2C69%40ME3P282MB1682.AUSP282.PROD.OUTLOOK.COM.
Reply all
Reply to author
Forward
0 new messages