标签:英雄 文件 OLE book 简单 code 继承 shel python
python manage.py startapp booktest
from django.db import models
class BookInfo(models.Model):
btitle = models.CharField(max_length=20)
bpub_date = models.DateTimeField()
def _ _str_ _(self):
return "%d" % self.pk
class HeroInfo(models.Model):
hname = models.CharField(max_length=20)
hgender = models.BooleanField()
hcontent = models.CharField(max_length=100)
hBook = models.ForeignKey(‘BookInfo‘)
def _ _str_ _(self):
return "%d" % self.pk
python manage.py makemigrations
python manage.py migrate
python manage.py shell
from booktest.models import BookInfo,HeroInfo
from django.utils import timezone
from datetime import *
BookInfo.objects.all()
b = BookInfo()
b.btitle="射雕英雄传"
b.bpub_date=datetime(year=1990,month=1,day=10)
b.save()
b=BookInfo.objects.get(pk=1)
b
b.id
b.btitle
b.btitle=u"天龙八部"
b.save()
b.delete()
h=HeroInfo()
h.htitle=u‘郭靖‘
h.hgender=True
h.hcontent=u‘降龙十八掌‘
h.hBook=b
h.save()
b.heroinfo_set.all()
h=b.heroinfo_set.create(htitle=u‘黄蓉‘,hgender=False,hcontent=u‘打狗棍法‘)
h
标签:英雄 文件 OLE book 简单 code 继承 shel python
原文地址:https://www.cnblogs.com/joshuazc/p/9533074.html