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
This commit is contained in:
Adrian Holovaty 2007-01-29 16:12:17 +00:00
parent d28a63cc00
commit 5aea495ac3
1 changed files with 1 additions and 1 deletions

View File

@ -37,7 +37,7 @@ def save_instance(form, instance, commit=True):
if commit: if commit:
instance.save() instance.save()
for f in opts.many_to_many: 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 # 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 # 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 # set on an object until after it's saved. Maybe we should raise an