@@ -167,9 +167,27 @@ About Queryset Methods
167
167
* ``distinct() `` works as expected. It only regards the fields of
168
168
the base class, but this should never make a difference.
169
169
170
- * ``select_related() `` works just as usual, but it can not (yet) be used
171
- to select relations in inherited models
172
- (like ``ModelA.objects.select_related('ModelC___fieldxy') `` )
170
+ * ``select_related() `` works just as usual with the exception that the
171
+ query set must be derived from a PolymorphicRelatedQuerySetMixin
172
+ or PolymorphicRelatedQuerySet.
173
+
174
+ This can be achieved by using a custom manager
175
+
176
+ class NonPolyModel(models.Model):
177
+ relation = models.ForeignKey(BasePolyModel, on_delete=models.CASCADE)
178
+ objects = models.Manager.from_queryset(PolymorphicRelatedQuerySet)()
179
+
180
+
181
+ To select related fields the model name comes after the field name and set the
182
+ field.
183
+ ``ModelA.objects.filter(....).select_related('field___TargetModel__subfield') ``.
184
+ or using the polymorphic added related fieldname which is normally the lowercase
185
+ version of the model name.
186
+ ``ModelA.objects.filter(....).select_related('field__targetmodel__subfield') ``
187
+
188
+ This automatically manages the via models between the model specified in the related
189
+ field and the target model.
190
+ ``ModelA.objects.filter(....).select_related('field__targetparentmodel__targetmodel__subfield') ``
173
191
174
192
* ``extra() `` works as expected (it returns polymorphic results) but
175
193
currently has one restriction: The resulting objects are required to have
0 commit comments