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

Тел: +7 965 3737 888

393

Просмотров

0

Ответов

Querying on existence of a relationship

<p>When you have two models joined by a foreign key, it's common to want to retrieve a set of objects from the "target" of the foreign key based on whether there are any objects "pointing" to them. This snippet demonstrates how to do so, using the extra method of the default model manager.</p>
<p>Note that this is probably more efficient than using two ORM methods (e.g., selecting all values from one table, and using an id__in lookup on the other) since it does the whole thing in one query and avoids instantiating any intermediate objects.</p>

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