Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved newforms.models.save_for_instance() to set many-to-many valu…

…es 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
  • Loading branch information...
commit 5aea495ac3a000a7b72fa3202e05ff35676e0e4e 1 parent d28a63c
@adrianholovaty adrianholovaty authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  django/newforms/models.py
View
2  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
Please sign in to comment.
Something went wrong with that request. Please try again.