1、新建一个APP

Python web开发——自定义userprofile(用户描述)

2、查看数据库中系统给我们提供的默认的users的字段含义

Python web开发——自定义userprofile(用户描述)

ID: 是主键,用户的ID

passWord:密码

last_login : 最后一次登录的时间

is_superuser:是否是超级用户(VIP)

username:用户姓名

first_name:扩展字段,初始值

email:用户的邮箱

is_staff:是否是员工

is_active:是否激活

data_joined:用户的注册时间

3、自定义userprofile

由于这些字段满足不了我们的需求,我们又想继承这些字段的同时,又想加入我们新的字段就要继承model中的abstractuser

Python web开发——自定义userprofile(用户描述)

按住Ctrl ,点击abstractuser  可以查看abstractuser的源码,通过源码可以看到,里面定义的都是数据库中的字段

Python web开发——自定义userprofile(用户描述)

 

4、添加自己的字段,定义一个类继承abstractuser,并添加自己需要的一些字段

Python web开发——自定义userprofile(用户描述)

 

 5、需要在setting 中注册我们所创建的APP

Python web开发——自定义userprofile(用户描述)

 

6、重载一个setting的方法,APP名.自定义的类名

Python web开发——自定义userprofile(用户描述)

7、运行 run

有报错

Python web开发——自定义userprofile(用户描述)

修改1、

Python web开发——自定义userprofile(用户描述)

修改2: 安装pillow

Python web开发——自定义userprofile(用户描述)

8、再次run

Python web开发——自定义userprofile(用户描述)

解决:migration 我们的APP

Python web开发——自定义userprofile(用户描述)

9、生成数据表

Python web开发——自定义userprofile(用户描述)

 输入  yes  回车(意思是 : 是否删除我们的user表)

10  进入数据库表查看我们创建的字段 (OK)

Python web开发——自定义userprofile(用户描述)

总结 : 我们用自定义的userProfile去替换之前的user,替换成功,

 

相关文章:

  • 2022-12-23
  • 2021-10-17
  • 2021-10-07
  • 2022-02-06
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
猜你喜欢
  • 2021-12-22
  • 2021-09-21
  • 2021-06-14
  • 2021-08-11
  • 2022-12-23
  • 2021-05-03
  • 2022-12-23
相关资源
相似解决方案