diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 2c060a0..0b941df 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
1107 | 1107 | else: |
1108 | 1108 | form_validated = False |
1109 | 1109 | new_object = self.model() |
1110 | | prefixes = {} |
1111 | | for FormSet, inline in zip(self.get_formsets(request), inline_instances): |
1112 | | prefix = FormSet.get_default_prefix() |
1113 | | prefixes[prefix] = prefixes.get(prefix, 0) + 1 |
1114 | | if prefixes[prefix] != 1 or not prefix: |
1115 | | prefix = "%s-%s" % (prefix, prefixes[prefix]) |
1116 | | formset = FormSet(data=request.POST, files=request.FILES, |
1117 | | instance=new_object, |
1118 | | save_as_new="_saveasnew" in request.POST, |
1119 | | prefix=prefix, queryset=inline.get_queryset(request)) |
1120 | | formsets.append(formset) |
| 1110 | formsets = self._create_formsets(request, new_object, inline_instances) |
1121 | 1111 | if all_valid(formsets) and form_validated: |
1122 | 1112 | self.save_model(request, new_object, form, False) |
1123 | 1113 | self.save_related(request, form, formsets, False) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1135 | 1125 | if isinstance(f, models.ManyToManyField): |
1136 | 1126 | initial[k] = initial[k].split(",") |
1137 | 1127 | form = ModelForm(initial=initial) |
1138 | | prefixes = {} |
1139 | | for FormSet, inline in zip(self.get_formsets(request), inline_instances): |
1140 | | prefix = FormSet.get_default_prefix() |
1141 | | prefixes[prefix] = prefixes.get(prefix, 0) + 1 |
1142 | | if prefixes[prefix] != 1 or not prefix: |
1143 | | prefix = "%s-%s" % (prefix, prefixes[prefix]) |
1144 | | formset = FormSet(instance=self.model(), prefix=prefix, |
1145 | | queryset=inline.get_queryset(request)) |
1146 | | formsets.append(formset) |
| 1128 | formsets = self._create_formsets(request, self.model(), inline_instances) |
1147 | 1129 | |
1148 | 1130 | adminForm = helpers.AdminForm(form, list(self.get_fieldsets(request)), |
1149 | 1131 | self.get_prepopulated_fields(request), |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1195 | 1177 | current_app=self.admin_site.name)) |
1196 | 1178 | |
1197 | 1179 | ModelForm = self.get_form(request, obj) |
1198 | | formsets = [] |
1199 | 1180 | inline_instances = self.get_inline_instances(request, obj) |
1200 | 1181 | if request.method == 'POST': |
1201 | 1182 | form = ModelForm(request.POST, request.FILES, instance=obj) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1205 | 1186 | else: |
1206 | 1187 | form_validated = False |
1207 | 1188 | new_object = obj |
1208 | | prefixes = {} |
1209 | | for FormSet, inline in zip(self.get_formsets(request, new_object), inline_instances): |
1210 | | prefix = FormSet.get_default_prefix() |
1211 | | prefixes[prefix] = prefixes.get(prefix, 0) + 1 |
1212 | | if prefixes[prefix] != 1 or not prefix: |
1213 | | prefix = "%s-%s" % (prefix, prefixes[prefix]) |
1214 | | formset = FormSet(request.POST, request.FILES, |
1215 | | instance=new_object, prefix=prefix, |
1216 | | queryset=inline.get_queryset(request)) |
1217 | | |
1218 | | formsets.append(formset) |
1219 | | |
| 1189 | formsets = self._create_formsets(request, new_object, inline_instances) |
1220 | 1190 | if all_valid(formsets) and form_validated: |
1221 | 1191 | self.save_model(request, new_object, form, True) |
1222 | 1192 | self.save_related(request, form, formsets, True) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1226 | 1196 | |
1227 | 1197 | else: |
1228 | 1198 | form = ModelForm(instance=obj) |
1229 | | prefixes = {} |
1230 | | for FormSet, inline in zip(self.get_formsets(request, obj), inline_instances): |
1231 | | prefix = FormSet.get_default_prefix() |
1232 | | prefixes[prefix] = prefixes.get(prefix, 0) + 1 |
1233 | | if prefixes[prefix] != 1 or not prefix: |
1234 | | prefix = "%s-%s" % (prefix, prefixes[prefix]) |
1235 | | formset = FormSet(instance=obj, prefix=prefix, |
1236 | | queryset=inline.get_queryset(request)) |
1237 | | formsets.append(formset) |
| 1199 | formsets = self._create_formsets(request, obj, inline_instances) |
1238 | 1200 | |
1239 | 1201 | adminForm = helpers.AdminForm(form, self.get_fieldsets(request, obj), |
1240 | 1202 | self.get_prepopulated_fields(request, obj), |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1533 | 1495 | "admin/object_history.html" |
1534 | 1496 | ], context, current_app=self.admin_site.name) |
1535 | 1497 | |
| 1498 | def _create_formsets(self, request, obj, inline_instances): |
| 1499 | "Helper function to generate formsets for add/change_view." |
| 1500 | formsets = [] |
| 1501 | prefixes = {} |
| 1502 | get_formsets_args = [request] |
| 1503 | if obj.pk: |
| 1504 | get_formsets_args.append(obj) |
| 1505 | for FormSet, inline in zip(self.get_formsets(*get_formsets_args), inline_instances): |
| 1506 | prefix = FormSet.get_default_prefix() |
| 1507 | prefixes[prefix] = prefixes.get(prefix, 0) + 1 |
| 1508 | if prefixes[prefix] != 1 or not prefix: |
| 1509 | prefix = "%s-%s" % (prefix, prefixes[prefix]) |
| 1510 | formset_params = { |
| 1511 | 'instance': obj, |
| 1512 | 'prefix': prefix, |
| 1513 | 'queryset': inline.get_queryset(request), |
| 1514 | } |
| 1515 | if request.method == 'POST': |
| 1516 | formset_params.update({ |
| 1517 | 'data': request.POST, |
| 1518 | 'files': request.FILES, |
| 1519 | 'save_as_new': '_saveasnew' in request.POST |
| 1520 | }) |
| 1521 | formsets.append(FormSet(**formset_params)) |
| 1522 | return formsets |
| 1523 | |
1536 | 1524 | |
1537 | 1525 | class InlineModelAdmin(BaseModelAdmin): |
1538 | 1526 | """ |