Navigation Menu

Skip to content

Commit

Permalink
Fixed metasystem bug when using get_related_many_to_many() method wit…
Browse files Browse the repository at this point in the history
…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 adaf046
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions django/core/meta/__init__.py
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions django/models/__init__.py
Expand Up @@ -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
Expand Down

0 comments on commit adaf046

Please sign in to comment.