diff options
Diffstat (limited to 'django/contrib/contenttypes/fields.py')
| -rw-r--r-- | django/contrib/contenttypes/fields.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index a3e87f6ed4..4905fd1fff 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -402,6 +402,20 @@ class GenericRelation(ForeignObject): ) ] + def get_local_related_value(self, instance): + return self.get_instance_value_for_fields(instance, self.foreign_related_fields) + + def get_foreign_related_value(self, instance): + # We (possibly) need to convert object IDs to the type of the + # instances' PK in order to match up instances during prefetching. + return tuple( + foreign_field.to_python(val) + for foreign_field, val in zip( + self.foreign_related_fields, + self.get_instance_value_for_fields(instance, self.local_related_fields), + ) + ) + def _get_path_info_with_parent(self, filtered_relation): """ Return the path that joins the current model through any parent models. |
