【发布时间】:2011-06-03 20:52:48
【问题描述】:
我在 django 中有以下模型结构。
Category:
- name
- description
Tag:
- name
Article:
- guid
- title
- detail
- tags (Many2Many with Tag)
- cats (Many2Many with Category)
现在,在我的批量(最多 100,000 篇)文章更新工作中,我必须执行以下操作。
- for each article:
- to check if this article has already appeared in another category
- if yes, associate article with current category
- if no, create article along current category
- to check if any of associated tags are exists or not,
- if not exists create tag, and associate with current article
- if exists, just associated with current article
在执行此操作时,我已经拥有从数据库中获取的现有文章的字典。
由于 ManyToMany 字段对 django 中的 select_related() 等获取操作没有任何影响,有没有其他方法可以帮助我加载现有文章以及类别和标签?
【问题讨论】:
标签: sql django performance django-models