Задать вопрос

Тел: +7 965 3737 888

446

Просмотров

1

Ответов

improved generic foreign key manager

<p>This is an improvement on <a href="http://foothold.ru/knowledge/detail/manager-method-for-limiting-genericforeignkey-queries.html">snippet 984</a>.  Read it's description and <a href="http://zerokspot.com/weblog/2008/08/13/genericforeignkeys-with-less-queries/">this blog post</a> for good explanations of the problem this solves.
</p>
<p>Unlike snippet 984, this version is able to handle multiple generic foreign keys, generic foreign keys with nonstandard ct_field and fk_field names, and avoids unnecessary lookups to the ContentType table.
</p>
<p>To use, just assign an instance of GFKManager as the objects attribute of a model that has generic foreign keys. Then:
</p>
MyModelWithGFKs.objects.filter(...).fetch_generic_relations()
<p>The generic related items will be bulk-fetched to minimize the number of queries.
</p>

Вопрос полезен? Да0/Нет0
file_3138.py(1.7Кб)
None

Ответы (1):

Ответtaddr:22.01.2009
Ответ полезен? Да0/Нет0

This definitely works. Thank you Carl!