Ticket #12238: dynamic-fieldsets-0.1.diff
File dynamic-fieldsets-0.1.diff, 1.9 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
58 58 fields = None 59 59 exclude = None 60 60 fieldsets = None 61 dynamic_fieldsets = None 61 62 form = forms.ModelForm 62 63 filter_vertical = () 63 64 filter_horizontal = () … … 318 319 319 320 def get_fieldsets(self, request, obj=None): 320 321 "Hook for specifying fieldsets for the add form." 322 if self.dynamic_fieldsets: 323 self.dynamic_fieldsets(request, obj) 321 324 if self.declared_fieldsets: 322 325 return self.declared_fieldsets 323 326 form = self.get_form(request, obj) … … 328 331 Returns a Form class for use in the admin add view. This is used by 329 332 add_view and change_view. 330 333 """ 331 if self.declared_fieldsets: 334 if self.dynamic_fieldsets: 335 fields = flatten_fieldsets(self.dynamic_fieldsets(request, obj, **kwargs)) 336 elif self.declared_fieldsets: 332 337 fields = flatten_fieldsets(self.declared_fieldsets) 333 338 else: 334 339 fields = None … … 1136 1141 1137 1142 def get_formset(self, request, obj=None, **kwargs): 1138 1143 """Returns a BaseInlineFormSet class for use in admin add/change views.""" 1144 if self.dynamic_fieldsets: 1145 fields = flatten_fieldsets(self.dynamic_fieldsets(request, obj)) 1139 1146 if self.declared_fieldsets: 1140 1147 fields = flatten_fieldsets(self.declared_fieldsets) 1141 1148 else: … … 1160 1167 return inlineformset_factory(self.parent_model, self.model, **defaults) 1161 1168 1162 1169 def get_fieldsets(self, request, obj=None): 1170 if self.dynamic_fieldsets: 1171 return self.dynamic_fieldsets(request, obj) 1163 1172 if self.declared_fieldsets: 1164 1173 return self.declared_fieldsets 1165 1174 form = self.get_formset(request).form