Ticket #4507: model-admin-save-hooks.diff
File model-admin-save-hooks.diff, 2.6 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
=== modified file 'django/contrib/admin/options.py'
318 318 from django.contrib.admin.models import LogEntry, ADDITION 319 319 from django.contrib.contenttypes.models import ContentType 320 320 opts = model._meta 321 new_object = form.save(commit=True) 322 323 if formsets: 324 for formset in formsets: 325 # HACK: it seems like the parent obejct should be passed into 326 # a method of something, not just set as an attribute 327 formset.instance = new_object 328 formset.save() 321 322 new_object = self.form_save_add(request, model, form, formsets) 329 323 330 324 pk_value = new_object._get_pk_val() 331 325 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), ADDITION) … … 367 361 from django.contrib.admin.models import LogEntry, CHANGE 368 362 from django.contrib.contenttypes.models import ContentType 369 363 opts = model._meta 370 new_object = form.save(commit=True) 364 365 new_object = self.form_save_change(request, model, form, formsets) 366 371 367 pk_value = new_object._get_pk_val() 372 368 373 if formsets:374 for formset in formsets:375 formset.save()376 377 369 # Construct the change message. TODO: Temporarily commented-out, 378 370 # as manipulator object doesn't exist anymore, and we don't yet 379 371 # have a way to get fields_added, fields_changed, fields_deleted. … … 406 398 request.user.message_set.create(message=msg) 407 399 return HttpResponseRedirect("../") 408 400 401 def form_save_add(self, request, model, form, formsets, commit=True): 402 return self.form_save(request, model, form, formsets, commit, True) 403 404 def form_save_change(self, request, model, form, formsets, commit=True): 405 return self.form_save(request, model, form, formsets, commit, False) 406 407 def form_save(self, request, model, form, formsets, commit, add): 408 object = form.save(commit=commit) 409 if formsets: 410 for formset in formsets: 411 if add: 412 # HACK: it seems like the parent object should be passed 413 # into a method of something, not just set as an attribute 414 formset.instance = object 415 formset.save() 416 return object 417 409 418 def add_view(self, request, form_url=''): 410 419 "The 'add' admin view for this model." 411 420 from django.contrib.admin.views.main import render_change_form