Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made GenericRelatedObjectManager consistent with other related manage…

…rs w.r.t. use of core_filters attribute.

Previously it had an unused keyword argument.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16914 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ec5bfed57ad86ec17a9169c279c967abbfbe52f9 1 parent 6d6fe61
@spookylukey spookylukey authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 django/contrib/contenttypes/generic.py
View
18 django/contrib/contenttypes/generic.py
@@ -214,6 +214,7 @@ def __get__(self, instance, instance_type=None):
RelatedManager = create_generic_related_manager(superclass)
qn = connection.ops.quote_name
+ content_type = ContentType.objects.db_manager(instance._state.db).get_for_model(instance)
manager = RelatedManager(
model = rel_model,
@@ -221,9 +222,14 @@ def __get__(self, instance, instance_type=None):
symmetrical = (self.field.rel.symmetrical and instance.__class__ == rel_model),
source_col_name = qn(self.field.m2m_column_name()),
target_col_name = qn(self.field.m2m_reverse_name()),
- content_type = ContentType.objects.db_manager(instance._state.db).get_for_model(instance),
+ content_type = content_type,
content_type_field_name = self.field.content_type_field_name,
- object_id_field_name = self.field.object_id_field_name
+ object_id_field_name = self.field.object_id_field_name,
+ core_filters = {
+ '%s__pk' % self.field.content_type_field_name: content_type.id,
+ '%s__exact' % self.field.object_id_field_name: instance._get_pk_val(),
+ }
+
)
return manager
@@ -249,7 +255,7 @@ def __init__(self, model=None, core_filters=None, instance=None, symmetrical=Non
content_type_field_name=None, object_id_field_name=None):
super(GenericRelatedObjectManager, self).__init__()
- self.core_filters = core_filters or {}
+ self.core_filters = core_filters
self.model = model
self.content_type = content_type
self.symmetrical = symmetrical
@@ -262,11 +268,7 @@ def __init__(self, model=None, core_filters=None, instance=None, symmetrical=Non
def get_query_set(self):
db = self._db or router.db_for_read(self.model, instance=self.instance)
- query = {
- '%s__pk' % self.content_type_field_name : self.content_type.id,
- '%s__exact' % self.object_id_field_name : self.pk_val,
- }
- return super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**query)
+ return super(GenericRelatedObjectManager, self).get_query_set().using(db).filter(**self.core_filters)
def add(self, *objs):
for obj in objs:
Please sign in to comment.
Something went wrong with that request. Please try again.