django多保存数据
来源:互联网 发布:湖北快三数据 编辑:程序博客网 时间:2024/04/30 18:42
django多保存数据
Saving ForeignKey and ManyToManyField fields
Updating a ForeignKey field works exactly the same way as saving a normal field -- simply assign an object of the right type to the field in question. This example updates the blog attribute of an Entry instance entry:
>>> from blog.models import Entry>>> entry = Entry.objects.get(pk=1)>>> cheese_blog = Blog.objects.get(name="Cheddar Talk")>>> entry.blog = cheese_blog>>> entry.save()
Updating a ManyToManyField works a little differently -- use the add() method on the field to add a record to the relation. This example adds the Author instance joe to the entry object:
>>> from blog.models import Author>>> joe = Author.objects.create(name="Joe")>>> entry.authors.add(joe)
To add multiple records to a ManyToManyField in one go, include multiple arguments in the call to add(), like this:
>>> john = Author.objects.create(name="John")>>> paul = Author.objects.create(name="Paul")>>> george = Author.objects.create(name="George")>>> ringo = Author.objects.create(name="Ringo")>>> entry.authors.add(john, paul, george, ringo)
- django多保存数据
- Django shell保存数据
- django中使用mongoengine保存字典结构的数据到数据库。
- Django REST framework 嵌套关系的数据保存(Writable nested serializers)
- 利用django中redisco库,修改redis模型导致数据无法保存以及部分其他问题
- django 利用PIL 保存图片
- 保存数据
- 保存数据
- 保存数据
- 数据保存
- 多并发下数据保存的问题
- 通过JSON保存多表单数据
- iOS数据保存-文件保存
- 保存数据 之 保存文件
- django 数据过滤
- django 数据排序
- Django接收Json数据
- Django性能数据优化
- 一纸红笺清花泪,半世琉璃山海盟:QQ伤感日志
- 二次函数计算程序
- Window Phone中使用本地数据库SQLCE的简单入门
- Oracle常用sql操作总结
- Android下JNI开发步骤 (转载)
- django多保存数据
- Java使用Google Calendar
- red hat Linux配置ip
- Step_in
- 灯红酒绿的伤感空间日志:也许,我们都不是真正的快乐
- 贷款计算
- SecureCRT 乱码
- Windows Phone 7 三种共享数据的方式
- 配置Windows服务器支持json文件的方法