Fixed metasystem bug when using get_related_many_to_many() method with a custom-named primary key. Thanks, stane
git-svn-id: http://code.djangoproject.com/svn/django/trunk@639 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
84560c7f84
commit
adaf046591
|
@ -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 mod in modules:
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue