Ticket #9150: create_update.py.diff
File create_update.py.diff, 2.5 KB (added by , 15 years ago) |
---|
-
django/views/generic/create_update.py
92 92 93 93 def create_object(request, model=None, template_name=None, 94 94 template_loader=loader, extra_context=None, post_save_redirect=None, 95 login_required=False, context_processors=None, form_class=None ):95 login_required=False, context_processors=None, form_class=None, form_params={}): 96 96 """ 97 97 Generic object-creation function. 98 98 … … 107 107 108 108 model, form_class = get_model_and_form_class(model, form_class) 109 109 if request.method == 'POST': 110 form = form_class( request.POST, request.FILES)110 form = form_class(data=request.POST, files=request.FILES, **form_params) 111 111 if form.is_valid(): 112 112 new_object = form.save() 113 113 if request.user.is_authenticated(): 114 114 request.user.message_set.create(message=ugettext("The %(verbose_name)s was created successfully.") % {"verbose_name": model._meta.verbose_name}) 115 115 return redirect(post_save_redirect, new_object) 116 116 else: 117 form = form_class( )117 form = form_class(**form_params) 118 118 119 119 # Create the template, context, response 120 120 if not template_name: … … 130 130 slug_field='slug', template_name=None, template_loader=loader, 131 131 extra_context=None, post_save_redirect=None, login_required=False, 132 132 context_processors=None, template_object_name='object', 133 form_class=None ):133 form_class=None, form_params={}): 134 134 """ 135 135 Generic object-update function. 136 136 … … 149 149 obj = lookup_object(model, object_id, slug, slug_field) 150 150 151 151 if request.method == 'POST': 152 form = form_class( request.POST, request.FILES, instance=obj)152 form = form_class(data=request.POST, files=request.FILES, instance=obj, **form_params) 153 153 if form.is_valid(): 154 154 obj = form.save() 155 155 if request.user.is_authenticated(): 156 156 request.user.message_set.create(message=ugettext("The %(verbose_name)s was updated successfully.") % {"verbose_name": model._meta.verbose_name}) 157 157 return redirect(post_save_redirect, obj) 158 158 else: 159 form = form_class(instance=obj )159 form = form_class(instance=obj, **form_params) 160 160 161 161 if not template_name: 162 162 template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())