Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #267 -- "Save and continue editing" no longer assumes object ha…

…s an ID field. Thanks, Hugo

git-svn-id: http://code.djangoproject.com/svn/django/trunk@400 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a8ecb56106736580270fc9f2bb1dc2d34c764cd7 1 parent 3f2df5e
Adrian Holovaty authored

Showing 1 changed file with 7 additions and 6 deletions. Show diff stats Hide diff stats

  1. 13  django/views/admin/main.py
13  django/views/admin/main.py
@@ -766,7 +766,8 @@ def add_stage(request, app_label, module_name, show_delete=False, form_url='', p
766 766
         if not errors and not request.POST.has_key("_preview"):
767 767
             manipulator.do_html2python(new_data)
768 768
             new_object = manipulator.save(new_data)
769  
-            log.log_action(request.user.id, opts.get_content_type_id(), getattr(new_object, opts.pk.name), repr(new_object), log.ADDITION)
  769
+            pk_value = getattr(new_object, opts.pk.name)
  770
+            log.log_action(request.user.id, opts.get_content_type_id(), pk_value, repr(new_object), log.ADDITION)
770 771
             msg = 'The %s "%s" was added successfully.' % (opts.verbose_name, new_object)
771 772
             # Here, we distinguish between different save types by checking for
772 773
             # the presence of keys in request.POST.
@@ -774,11 +775,10 @@ def add_stage(request, app_label, module_name, show_delete=False, form_url='', p
774 775
                 request.user.add_message("%s You may edit it again below." % msg)
775 776
                 if request.POST.has_key("_popup"):
776 777
                     post_url_continue += "?_popup=1"
777  
-                return HttpResponseRedirect(post_url_continue % new_object.id)
  778
+                return HttpResponseRedirect(post_url_continue % pk_value)
778 779
             if request.POST.has_key("_popup"):
779 780
                 return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \
780  
-                    (getattr(new_object, opts.pk.name), repr(new_object).replace('"', '\\"')),
781  
-                    mimetype='text/html; charset=utf-8')
  781
+                    (pk_value, repr(new_object).replace('"', '\\"')), mimetype='text/html; charset=utf-8')
782 782
             elif request.POST.has_key("_addanother"):
783 783
                 request.user.add_message("%s You may add another %s below." % (msg, opts.verbose_name))
784 784
                 return HttpResponseRedirect(request.path)
@@ -862,6 +862,7 @@ def change_stage(request, app_label, module_name, object_id):
862 862
         if not errors and not request.POST.has_key("_preview"):
863 863
             manipulator.do_html2python(new_data)
864 864
             new_object = manipulator.save(new_data)
  865
+            pk_value = getattr(new_object, opts.pk.name)
865 866
 
866 867
             # Construct the change message.
867 868
             change_message = []
@@ -875,7 +876,7 @@ def change_stage(request, app_label, module_name, object_id):
875 876
             if not change_message:
876 877
                 change_message = 'No fields changed.'
877 878
 
878  
-            log.log_action(request.user.id, opts.get_content_type_id(), getattr(new_object, opts.pk.name), repr(new_object), log.CHANGE, change_message)
  879
+            log.log_action(request.user.id, opts.get_content_type_id(), pk_value, repr(new_object), log.CHANGE, change_message)
879 880
             msg = 'The %s "%s" was changed successfully.' % (opts.verbose_name, new_object)
880 881
             if request.POST.has_key("_continue"):
881 882
                 request.user.add_message("%s You may edit it again below." % msg)
@@ -885,7 +886,7 @@ def change_stage(request, app_label, module_name, object_id):
885 886
                     return HttpResponseRedirect(request.path)
886 887
             elif request.POST.has_key("_saveasnew"):
887 888
                 request.user.add_message('The %s "%s" was added successfully. You may edit it again below.' % (opts.verbose_name, new_object))
888  
-                return HttpResponseRedirect("../%s/" % new_object.id)
  889
+                return HttpResponseRedirect("../%s/" % pk_value)
889 890
             elif request.POST.has_key("_addanother"):
890 891
                 request.user.add_message("%s You may add another %s below." % (msg, opts.verbose_name))
891 892
                 return HttpResponseRedirect("../add/")

0 notes on commit a8ecb56

Please sign in to comment.
Something went wrong with that request. Please try again.