ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**Models.py配置示例** 1、修改guigu models.py 根据项目要求设置 models ~~~ #models样板 # _*_ coding:utf-8 _*_ from __future__ import unicode_literals from datetime import datetime #引入时间模块 from django.contrib.auth.models import User#引入自带User模块 from django.db import models # Create your models here. #创建文章管理class class Blogs(models.Model): title = models.CharField(max_length=500, verbose_name=u"标题") author = models.ForeignKey(User, related_name="blog_posts", verbose_name=u"作者") body = models.TextField(verbose_name=u"内容") publish = models.DateTimeField(default=datetime.now, verbose_name=u"时间") class Meta: verbose_name = u"文章管理" verbose_name_plural = verbose_name def __str__(self): return self.title ~~~ **Models配置扩展** ~~~ #会员注册 from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import User#引入自带User #会员信息 class UserInfo(models.Model): #OneToOneField()含义是通过User这个字段声明UserInfo类与User之间的关系是“一对一”的。 user = models.OneToOneField(User, unique=True, verbose_name=u"帐号") image = models.ImageField(upload_to="image/%Y/m", default=u"image/default.png", max_length=100, verbose_name=u"头像") user_name = models.CharField(max_length=100, blank=True, verbose_name=u"姓名") phone = models.CharField(max_length=11, blank=True, verbose_name=u"手机号") WeChat = models.CharField(max_length=20, blank=True, verbose_name=u"微信号") payment = models.CharField(max_length=20, choices=(("Alipay", u"支付宝"),("WeChat", U"微信帐号")), default="Alipay", verbose_name=u"提现方式") accounts = models.CharField(max_length=20, blank=True, verbose_name=u"支付帐号") balance = models.CharField(max_length=20, blank=True, verbose_name=u"余额") class Meta: verbose_name = u"用户信息" verbose_name_plural = verbose_name def __str__(self): return "user:{}".format(self.user.username) ~~~ ~~~ #ForeignKey数据绑定 # _*_ coding:utf-8 _*_ from __future__ import unicode_literals from django.db import models from users.models import Referee # Create your models here. class Bank(models.Model): nick_name = models.ForeignKey(Referee, verbose_name=u"昵称") Alipay = models.CharField(max_length=100, verbose_name=u"支付宝") WeChat = models.CharField(max_length=100, verbose_name=u"微信") balance = models.IntegerField(default=0, verbose_name=u"余额") class Meta: verbose_name = "佣金结算" verbose_name_plural = verbose_name ~~~ 2、生成数据表 `makemigrations` `migrate`