Ticket #8005: 8005.2.diff
File 8005.2.diff, 3.0 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/options.py
324 324 def get_formsets(self, request, obj=None): 325 325 for inline in self.inline_instances: 326 326 yield inline.get_formset(request, obj) 327 327 328 def save_formset_add(self, request, formset, new_object): 329 # HACK: it seems like the parent obejct should be passed into 330 # a method of something, not just set as an attribute 331 formset.instance = new_object 332 formset.save() 333 334 def save_model_add(self, request, form, formsets): 335 return form.save(commit=True) 336 328 337 def save_add(self, request, form, formsets, post_url_continue): 329 338 """ 330 339 Saves the object in the "add" stage and returns an HttpResponseRedirect. … … 333 342 """ 334 343 from django.contrib.admin.models import LogEntry, ADDITION 335 344 opts = self.model._meta 336 new_object = form.save(commit=True) 337 345 346 new_object = self.save_model_add(request, form, formsets) 347 338 348 if formsets: 339 349 for formset in formsets: 340 # HACK: it seems like the parent obejct should be passed into 341 # a method of something, not just set as an attribute 342 formset.instance = new_object 343 formset.save() 344 350 self.save_formset_add(request, formset, new_object) 351 345 352 pk_value = new_object._get_pk_val() 346 353 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(self.model).id, pk_value, force_unicode(new_object), ADDITION) 347 354 msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': opts.verbose_name, 'obj': new_object} … … 371 378 post_url = '../../../' 372 379 return HttpResponseRedirect(post_url) 373 380 save_add = transaction.commit_on_success(save_add) 374 381 382 def save_formset_change(self, request, formset, new_object): 383 formset.save() 384 385 def save_model_change(self, request, form, formsets): 386 return form.save(commit=True) 387 375 388 def save_change(self, request, form, formsets=None): 376 389 """ 377 390 Saves the object in the "change" stage and returns an HttpResponseRedirect. … … 382 395 """ 383 396 from django.contrib.admin.models import LogEntry, CHANGE 384 397 opts = self.model._meta 385 new_object = form.save(commit=True)386 pk_value = new_object._get_pk_val()387 398 399 new_object = self.save_model_change(request, form, formsets) 400 388 401 if formsets: 389 402 for formset in formsets: 390 formset.save() 391 403 self.save_formset_change(self, request, formset, new_object) 404 405 pk_value = new_object._get_pk_val() 406 392 407 # Construct the change message. 393 408 change_message = [] 394 409 if form.changed_data: