Ticket #7973: 7973.exclude.diff
File 7973.exclude.diff, 3.4 KB (added by , 16 years ago) |
---|
-
django/django/contrib/admin/options.py
116 116 raw_id_fields = () 117 117 fields = None 118 118 fieldsets = None 119 exclude = None 119 120 form = forms.ModelForm 120 121 filter_vertical = () 121 122 filter_horizontal = () … … 319 320 fields = flatten_fieldsets(self.declared_fieldsets) 320 321 else: 321 322 fields = None 322 return modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=self.formfield_for_dbfield )323 return modelform_factory(self.model, form=self.form, fields=fields, formfield_callback=self.formfield_for_dbfield, exclude=self.exclude) 323 324 324 325 def get_formsets(self, request, obj=None): 325 326 for inline in self.inline_instances: … … 726 727 return inlineformset_factory(self.parent_model, self.model, 727 728 form=self.form, formset=self.formset, fk_name=self.fk_name, 728 729 fields=fields, formfield_callback=self.formfield_for_dbfield, 729 extra=self.extra, max_num=self.max_num )730 extra=self.extra, max_num=self.max_num, exclude=self.exclude) 730 731 731 732 def get_fieldsets(self, request, obj=None): 732 733 if self.declared_fieldsets: -
django/tests/regressiontests/modeladmin/models.py
162 162 163 163 >>> band2.delete() 164 164 165 166 Using 'exclude'. 167 >>> class BandAdmin(ModelAdmin): 168 ... exclude = ['bio'] 169 >>> ma = BandAdmin(Band, site) 170 >>> ma.get_form(request).base_fields.keys() 171 ['name', 'sign_date'] 172 173 Using 'fields' *and* 'exclude'. 174 >>> class BandAdmin(ModelAdmin): 175 ... fields = ['name', 'bio'] 176 ... exclude = ['bio'] 177 >>> ma = BandAdmin(Band, site) 178 >>> ma.get_form(request).base_fields.keys() 179 ['name'] 180 181 165 182 # radio_fields behavior ################################################ 166 183 167 184 First, without any radio_fields specified, the widgets for ForeignKey -
django/docs/admin.txt
147 147 ``django.utils.html.escape()`` to escape any HTML special 148 148 characters. 149 149 150 ``exclude`` 151 ~~~~~~~~~~~ 152 153 This attribute, if given, should be a list of field names to exclude from the form. 154 155 For example, let's consider the following model:: 156 157 class Author(models.Model): 158 name = models.CharField(max_length=100) 159 title = models.CharField(max_length=3) 160 birth_date = models.DateField(blank=True, null=True) 161 162 If you want a form for the ``Author`` model that includes only the ``name`` and ``title`` 163 fields, you would specify ``fields`` or ``exclude`` like this:: 164 165 class AuthorAdmin(admin.ModelAdmin): 166 fields = ('name', 'title') 167 168 class AuthorAdmin(admin.ModelAdmin): 169 exclude = ('birth_date',) 170 171 Since the Author model only has 3 fields, 'name', 'title', and 'birth_date', the forms 172 resulting from the above declarations will contain exactly the same fields. 173 150 174 ``filter_horizontal`` 151 175 ~~~~~~~~~~~~~~~~~~~~~ 152 176