Ticket #12755: modeladmin_get_form_instance.patch
File modeladmin_get_form_instance.patch, 2.5 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
363 363 defaults.update(kwargs) 364 364 return modelform_factory(self.model, **defaults) 365 365 366 def get_form_instance(self, request, form_class, **kwargs): 367 """ 368 Returns a Form instance for use in the admin ``add_view`` and ``change_view``. The 369 ``form_class`` parameter is returned by ``get_form()`` 370 """ 371 return form_class(**kwargs) 372 366 373 def get_changelist(self, request, **kwargs): 367 374 """ 368 375 Returns the ChangeList class for use on the changelist page. … … 767 774 ModelForm = self.get_form(request) 768 775 formsets = [] 769 776 if request.method == 'POST': 770 form = ModelForm(request.POST,request.FILES)777 form = self.get_form_instance(request, ModelForm, data=request.POST, files=request.FILES) 771 778 if form.is_valid(): 772 779 new_object = self.save_form(request, form, change=False) 773 780 form_validated = True … … 804 811 continue 805 812 if isinstance(f, models.ManyToManyField): 806 813 initial[k] = initial[k].split(",") 807 form = ModelForm(initial=initial)814 form = self.get_form_instance(request, ModelForm, initial=initial) 808 815 prefixes = {} 809 816 for FormSet, inline in zip(self.get_formsets(request), 810 817 self.inline_instances): … … 865 872 ModelForm = self.get_form(request, obj) 866 873 formsets = [] 867 874 if request.method == 'POST': 868 form = ModelForm(request.POST, request.FILES, instance=obj) 875 form = self.get_form_instance(request, ModelForm, data=request.POST, 876 files=request.FILES, instance=obj) 869 877 if form.is_valid(): 870 878 form_validated = True 871 879 new_object = self.save_form(request, form, change=True) … … 896 904 return self.response_change(request, new_object) 897 905 898 906 else: 899 form = ModelForm(instance=obj)907 form = self.get_form_instance(request, ModelForm, instance=obj) 900 908 prefixes = {} 901 909 for FormSet, inline in zip(self.get_formsets(request, obj), self.inline_instances): 902 910 prefix = FormSet.get_default_prefix()