阅读背景:

django:在没有中间模型的情况下迭代ManyToMany表中的项目(不使用'through')

来源:互联网 

I have a simple case with 2 models: Item and Category with ManyToMany between them. I want to show a page listing all categories and for each category list of items. I have hundreds of categories so django hits db hundreds of times (when iterating thru categories and calling items.all() for each one). I need to select data from the intermediate table manually and use select_related() to pull item and category for each record - one query instead of hundreds. I have a simple case with 2 models: Item and Ca




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: