模型二
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模型二相关的知识,希望对你有一定的参考价值。
基本的数据访问 直接上代码吧 比较简单的操作。
>>> from book.models import Publisher >>> p1 = Publisher(name=‘Apress‘, address=‘2855 Telegraph Avenue‘,city=‘Berkeley‘, state_province=‘CA‘, country=‘U.S.A.‘,website=‘http://www.apress.com/‘) >>> p1.save() >>> p2 = Publisher(name="O‘Reilly", address=‘10 Fawcett St.‘,city=‘Cambridge‘, state_province=‘MA‘, country=‘U.S.A.‘,website=‘http://www.oreilly.com/‘) >>> p2.save() >>> publisher_list = Publisher.objects.all() >>> publisher_list <QuerySet [<Publisher: Publisher object>, <Publisher: Publisher object>]> >>> type(publisher_list) <class ‘django.db.models.query.QuerySet‘> >>> for i in publisher_list: ... i ... <Publisher: Publisher object> <Publisher: Publisher object> >>> for i in publisher_list: ... i.name ... ‘Apress‘ "O‘Reilly" >>> Publisher.objects.create(name="O‘Yuqn", address=‘11 Fawcett St.‘,city=‘Cambridge‘, state_province=‘MA‘, country=‘U.S.A.‘,website=‘http://www.oreilly.com/‘)<Publisher: Publisher object> >>> Publisher.objects.create(name="O‘Y11uqn", address=‘11 Fa11wcett St.‘,city=‘11Cambridge‘, state_province=‘11MA‘, country=‘U.111S.A.‘,website=‘http://www.orei11lly.com/‘) <Publisher: Publisher object> >>> publisher_list = Publisher.objects.all() >>> for i in publisher_list: ... i.name ... ‘Apress‘ "O‘Reilly" "O‘Yuqn" "O‘Y11uqn"
如果我们要删除对象的话,删除数据库中的对象只需调用该对象的delete()方法即可:
>>> p = Publisher.objects.get(name="O‘Reilly") >>> p.delete() >>> Publisher.objects.filter(country=‘USA‘).delete() >>> Publisher.objects.all().delete()
更新对象,很简单,先获取对象然后将其当做一般的变量进行赋值即可。当然还是要保存的。
>>> p.name = ‘Apress Publishing‘ >>> p.save()
以上是关于模型二的主要内容,如果未能解决你的问题,请参考以下文章
二代下机文件在Integrative Genomics Viewer中实现reads可视化的流程
Android 逆向加壳技术简介 ( 动态加载 | 第一代加壳技术 - DEX 整体加固 | 第二代加壳技术 - 函数抽取 | 第三代加壳技术 - VMP / Dex2C | 动态库加壳技术 )