重点返回类型要这样写,returnu'%s'%self.qq否则类型不对会报错,
如果类型对在后也是必填项,用上面写法才能正常
#注册用户
from django.db import models
class User(models.Model):
username = models.CharField(verbose_name='昵称',max_length=100,blank=True,null=True)
phone = models.CharField(verbose_name='手机',max_length=100,blank=True,null=True)
password = models.CharField(verbose_name='密码',max_length=100,blank=True,null=True)
def__str__(self):
returnu'%s,%s'% (self.username,self.phone)
classMeta:
verbose_name ='注册用户'
verbose_name_plural ="注册用户"
# 基本资料
classBasic(models.Model):
user = models.OneToOneField(User,verbose_name='选择用户')
email = models.EmailField(verbose_name='邮箱',db_index=True,blank=True,null=True)#db_index=True数据库索引
qq = models.CharField(verbose_name='QQ', max_length=32,blank=True,null=True)
wx = models.CharField(verbose_name='微信', max_length=32,blank=True,null=True)
alipay = models.CharField(verbose_name='支付宝', max_length=32,blank=True,null=True)
def__str__(self):
returnu'%s'%self.qq
classMeta:
verbose_name ='基本资料'
verbose_name_plural ="基本资料"