Refs #30493 -- Added GenericRelatedObjectManager.get_content_type() hook.
This commit is contained in:
parent
ea6e684f34
commit
f66021f3f7
|
@ -1,3 +1,4 @@
|
||||||
|
import functools
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
@ -515,17 +516,18 @@ def create_generic_related_manager(superclass, rel):
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
|
|
||||||
self.model = rel.model
|
self.model = rel.model
|
||||||
|
self.get_content_type = functools.partial(
|
||||||
content_type = ContentType.objects.db_manager(instance._state.db).get_for_model(
|
ContentType.objects.db_manager(instance._state.db).get_for_model,
|
||||||
instance, for_concrete_model=rel.field.for_concrete_model)
|
for_concrete_model=rel.field.for_concrete_model,
|
||||||
self.content_type = content_type
|
)
|
||||||
|
self.content_type = self.get_content_type(instance)
|
||||||
self.content_type_field_name = rel.field.content_type_field_name
|
self.content_type_field_name = rel.field.content_type_field_name
|
||||||
self.object_id_field_name = rel.field.object_id_field_name
|
self.object_id_field_name = rel.field.object_id_field_name
|
||||||
self.prefetch_cache_name = rel.field.attname
|
self.prefetch_cache_name = rel.field.attname
|
||||||
self.pk_val = instance.pk
|
self.pk_val = instance.pk
|
||||||
|
|
||||||
self.core_filters = {
|
self.core_filters = {
|
||||||
'%s__pk' % self.content_type_field_name: content_type.id,
|
'%s__pk' % self.content_type_field_name: self.content_type.id,
|
||||||
self.object_id_field_name: self.pk_val,
|
self.object_id_field_name: self.pk_val,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue