django框架自定义用户表操作示例
作者:站在两个世界的边缘 时间:2021-10-04 04:29:54
本文实例讲述了django框架自定义用户表操作。分享给大家供大家参考,具体如下:
django中已经给我生成默认的User表,其中的字段已经可以满足我们的日常需求。
但有时候,我们需要更多的字段,我们就可以自定义。来替换django自带的User表。
models.py
from django.contrib.auth.models import AbstractUser
class UserProfile(AbstractUser):
nick_name = models.CharField(max_length=50, verbose_name=u'昵称')
birthday = models.DateField(verbose_name=u'生日', null=True, blank=True)
gender = models.CharField(max_length=10, choices=(("male", u'男'), ("female", u'女')), default='female')
address = models.CharField(max_length=11, verbose_name=u'地址', null=True, blank=True)
image = models.ImageField(upload_to='image/%Y/%m', default=u"image/default.png", max_length=100)
phone = models.CharField(max_length=11, verbose_name=u"手机号码", null=True, blank=True)
# image依赖Pillow
class Meta:
verbose_name = u"用户信息"
verbose_name_plural = verbose_name
def __unicode__(self):
return self.username
adminx.py
from xadmin.plugins.auth import UserAdmin
class UserProfileAdmin(UserAdmin):
pass
settings.py
INSTALLED_APPS = [
...
'users',
....
]
AUTH_USER_MODEL="users.UserProfile"
然后就可以makemigrations,migrate
然后就可以创建超级用户。如果之前创建过,会被删除,需要重新创建。
希望本文所述对大家基于Django框架的Python程序设计有所帮助。
来源:https://www.cnblogs.com/wongbingming/p/7125713.html
标签:django框架,自定义,用户表
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python怎么提高计算速度
2021-06-09 17:04:42
通过实例学习Python Excel操作
2021-01-21 21:55:12
![](https://img.aspxhome.com/file/2023/2/78782_0s.png)
提醒各位一下,IE透明会失效的
2009-03-31 12:48:00
![](https://img.aspxhome.com/file/UploadPic/20093/31/icon_lol-37s.gif)
ASP+JavaScript的完整的日历使用
2008-10-11 12:16:00
python eventlet绿化和patch原理
2022-02-22 11:10:14
Python数学建模PuLP库线性规划实际案例编程详解
2021-04-29 19:12:56
asp 删除数据库记录的代码
2011-02-05 10:39:00
python Shapely使用指南详解
2022-11-01 23:38:04
解决Python3中二叉树前序遍历的迭代问题
2022-04-11 09:05:24
![](https://img.aspxhome.com/file/2023/8/103308_0s.png)
ASP与Excel结合生成数据表和Chart图的代码
2011-03-08 10:50:00
Python中match语句的详细用法实例
2023-06-29 11:28:46
![](https://img.aspxhome.com/file/2023/7/60517_0s.png)
BOF、EOF 属性
2009-05-11 12:37:00
VBScript中清除数组元素Erase语句
2008-06-27 13:05:00
Pycharm安装scrapy及初始化爬虫项目的完整步骤
2023-04-03 10:49:43
![](https://img.aspxhome.com/file/2023/4/108114_0s.jpg)
Python 如何将integer转化为罗马数(3999以内)
2023-01-19 12:46:51
利用XMLHTTP检测网址及探测服务器类型
2009-04-24 15:12:00
Python smtplib实现发送邮件功能
2021-02-14 20:07:26
python之pyqt5通过按钮改变Label的背景颜色方法
2021-04-03 22:59:52
![](https://img.aspxhome.com/file/2023/7/95717_0s.jpg)
python可视化分析绘制带趋势线的散点图和边缘直方图
2023-08-16 04:10:10
![](https://img.aspxhome.com/file/2023/0/77900_0s.png)
使用Pytorch+PyG实现MLP的详细过程
2023-05-03 17:48:14
![](https://img.aspxhome.com/file/2023/0/110210_0s.png)