Permalink
Browse files

Fixed metasystem bug when using get_related_many_to_many() method wit…

…h a custom-named primary key. Thanks, stane

git-svn-id: http://code.djangoproject.com/svn/django/trunk@639 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
adrianholovaty committed Sep 13, 2005
1 parent 84560c7 commit adaf046591c087adb3ca31cd8ea901ed525918df
Showing with 5 additions and 5 deletions.
  1. +2 −2 django/core/meta/__init__.py
  2. +3 −3 django/models/__init__.py
@@ -947,8 +947,8 @@ def method_add_related(rel_obj, rel_mod, rel_field, self, *args, **kwargs):
# Handles related many-to-many object retrieval.
# Examples: Album.get_song(), Album.get_song_list(), Album.get_song_count()
-def method_get_related_many_to_many(method_name, rel_mod, rel_field, self, **kwargs):
- kwargs['%s__id__exact' % rel_field.name] = self.id
+def method_get_related_many_to_many(method_name, opts, rel_mod, rel_field, self, **kwargs):
+ kwargs['%s__%s__exact' % (rel_field.name, opts.pk.name)] = getattr(self, opts.pk.column)
return getattr(rel_mod, method_name)(**kwargs)
# Handles setting many-to-many related objects.
@@ -62,9 +62,9 @@
for rel_opts, rel_field in klass._meta.get_all_related_many_to_many_objects():
rel_mod = rel_opts.get_model_module()
rel_obj_name = klass._meta.get_rel_object_method_name(rel_opts, rel_field)
- setattr(klass, 'get_%s' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_object', rel_mod, rel_field))
- setattr(klass, 'get_%s_count' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_count', rel_mod, rel_field))
- setattr(klass, 'get_%s_list' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_list', rel_mod, rel_field))
+ setattr(klass, 'get_%s' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_object', klass._meta, rel_mod, rel_field))
+ setattr(klass, 'get_%s_count' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_count', klass._meta, rel_mod, rel_field))
+ setattr(klass, 'get_%s_list' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_list', klass._meta, rel_mod, rel_field))
if rel_opts.app_label == klass._meta.app_label:
func = curry(meta.method_set_related_many_to_many, rel_opts, rel_field)
func.alters_data = True

0 comments on commit adaf046

Please sign in to comment.