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.

https://docs.djangoproject.com/en/4.0/ref/contrib/auth/

On Mon, 9 May 2022 at 21:18, 郑 玉婷 <molly.zheng.w...@outlook.com> wrote:

> 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. I’ll 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
>
>
>
>
>
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ME3P282MB1682636F0E189716B7A32546D2C69%40ME3P282MB1682.AUSP282.PROD.OUTLOOK.COM
> <https://groups.google.com/d/msgid/django-users/ME3P282MB1682636F0E189716B7A32546D2C69%40ME3P282MB1682.AUSP282.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFKhtoRvF_zHjHdNSx1NWh%2BSXBPWR7BC5WW%2BLLt44MTQAyHFCQ%40mail.gmail.com.

Reply via email to