您的位置:首页 > 数据库

Django:一些数据库操作的指令(持续完善)

2014-01-20 00:16 232 查看
1、ManyToOne

例如有两个类之间是many-to-one的关系(question and answer)

(1)访问:

从answer访问question非常容易,而从question访问answer则需要:

question.answer_set.all()

(2)添加:

给question添加answer可以使用:

one_of_the_questions.answer_set.add(new_answer)
one_of_the_questions.answer_set.create(------)

如此做是可以不需要再使用save()的方法

(3)删除:

q.answer_set.remove(a)
q.answer_set.clear()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django python