From 5aea495ac3a000a7b72fa3202e05ff35676e0e4e Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 29 Jan 2007 16:12:17 +0000 Subject: [PATCH] Improved newforms.models.save_for_instance() to set many-to-many values via ID instead of instance, to save on a database query, thanks to [4448] git-svn-id: http://code.djangoproject.com/svn/django/trunk@4449 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/newforms/models.py b/django/newforms/models.py index 9bd6a3ff838..a938b6350e2 100644 --- a/django/newforms/models.py +++ b/django/newforms/models.py @@ -37,7 +37,7 @@ def save_instance(form, instance, commit=True): if commit: instance.save() for f in opts.many_to_many: - setattr(instance, f.attname, getattr(instance, f.attname).model.objects.filter(pk__in = clean_data[f.name])) + setattr(instance, f.attname, clean_data[f.name]) # GOTCHA: If many-to-many data is given and commit=False, the many-to-many # data will be lost. This happens because a many-to-many options cannot be # set on an object until after it's saved. Maybe we should raise an