Check the type of object passed to query relations.
(self, field, value, opts)
| 1376 | ) |
| 1377 | |
| 1378 | def check_related_objects(self, field, value, opts): |
| 1379 | """Check the type of object passed to query relations.""" |
| 1380 | if field.is_relation: |
| 1381 | # Check that the field and the queryset use the same model in a |
| 1382 | # query like .filter(author=Author.objects.all()). For example, the |
| 1383 | # opts would be Author's (from the author field) and value.model |
| 1384 | # would be Author.objects.all() queryset's .model (Author also). |
| 1385 | # The field is the related field on the lhs side. |
| 1386 | if ( |
| 1387 | isinstance(value, Query) |
| 1388 | and not value.has_select_fields |
| 1389 | and not check_rel_lookup_compatibility(value.model, opts, field) |
| 1390 | ): |
| 1391 | raise ValueError( |
| 1392 | 'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' |
| 1393 | % (value.model._meta.object_name, opts.object_name) |
| 1394 | ) |
| 1395 | elif hasattr(value, "_meta"): |
| 1396 | self.check_query_object_type(value, opts, field) |
| 1397 | elif hasattr(value, "__iter__"): |
| 1398 | for v in value: |
| 1399 | self.check_query_object_type(v, opts, field) |
| 1400 | |
| 1401 | def check_filterable(self, expression): |
| 1402 | """Raise an error if expression cannot be used in a WHERE clause.""" |
no test coverage detected