Django的models方法返回值异常,待解决
class BookInfo(models.Model): #创建书本信息类,继承models.Model booktitle=models.CharField(max_length=20) bookdata=models.DateField() def __unicode__(self): return self.booktitle
class HeroInfo(models.Model): #创建英雄信息类
heroname=models.CharField(max_length=10)
herosex=models.CharField(max_length=1)
herocontent=models.CharField(max_length=50)
herobook=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) #引用外键,即BookInfo对象
def __unicode__(self):
return self.heroname
后台HeroInfo的herobook作为外键的BookInfo的返回为:BookInfo object (1)
更多内容详见微信公众号:Python研究所
![Python研究所](https://images.cnblogs.com/cnblogs_com/phyger/1864462/o_201016034153qrcode_for_gh_8f86fc2ac31a_258.jpg)