Changeset 8861
- Timestamp:
- 09/02/08 12:26:24 (4 months ago)
- Files:
-
- django/trunk/django/contrib/admin/options.py (modified) (4 diffs)
- django/trunk/docs/ref/contrib/admin.txt (modified) (1 diff)
- django/trunk/tests/modeltests/model_formsets/models.py (modified) (1 diff)
- django/trunk/tests/regressiontests/modeladmin/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/admin/options.py
r8773 r8861 32 32 raw_id_fields = () 33 33 fields = None 34 exclude = None 34 35 fieldsets = None 35 36 form = forms.ModelForm … … 263 264 else: 264 265 fields = None 266 if self.exclude is None: 267 exclude = [] 268 else: 269 exclude = self.exclude 265 270 defaults = { 266 271 "form": self.form, 267 272 "fields": fields, 273 "exclude": exclude + kwargs.get("exclude", []), 268 274 "formfield_callback": self.formfield_for_dbfield, 269 275 } … … 781 787 else: 782 788 fields = None 789 if self.exclude is None: 790 exclude = [] 791 else: 792 exclude = self.exclude 783 793 defaults = { 784 794 "form": self.form, … … 786 796 "fk_name": self.fk_name, 787 797 "fields": fields, 798 "exclude": exclude + kwargs.get("exclude", []), 788 799 "formfield_callback": self.formfield_for_dbfield, 789 800 "extra": self.extra, django/trunk/docs/ref/contrib/admin.txt
r8858 r8861 181 181 dictionary key that is within the ``fieldsets`` option, as described in 182 182 the previous section. 183 184 ``exclude`` 185 ~~~~~~~~~~~ 186 187 This attribute, if given, should be a list of field names to exclude from the 188 form. 189 190 For example, let's consider the following model:: 191 192 class Author(models.Model): 193 name = models.CharField(max_length=100) 194 title = models.CharField(max_length=3) 195 birth_date = models.DateField(blank=True, null=True) 196 197 If you want a form for the ``Author`` model that includes only the ``name`` 198 and ``title`` fields, you would specify ``fields`` or ``exclude`` like this:: 199 200 class AuthorAdmin(admin.ModelAdmin): 201 fields = ('name', 'title') 202 203 class AuthorAdmin(admin.ModelAdmin): 204 exclude = ('birth_date',) 205 206 Since the Author model only has three fields, ``name``, ``title``, and 207 ``birth_date``, the forms resulting from the above declarations will contain 208 exactly the same fields. 183 209 184 210 ``filter_horizontal`` django/trunk/tests/modeltests/model_formsets/models.py
r8816 r8861 702 702 True 703 703 704 705 704 """} django/trunk/tests/regressiontests/modeladmin/models.py
r8604 r8861 117 117 118 118 119 # Using `exclude`. 120 121 >>> class BandAdmin(ModelAdmin): 122 ... exclude = ['bio'] 123 >>> ma = BandAdmin(Band, site) 124 >>> ma.get_form(request).base_fields.keys() 125 ['name', 'sign_date'] 126 127 # Using `fields` and `exclude`. 128 129 >>> class BandAdmin(ModelAdmin): 130 ... fields = ['name', 'bio'] 131 ... exclude = ['bio'] 132 >>> ma = BandAdmin(Band, site) 133 >>> ma.get_form(request).base_fields.keys() 134 ['name'] 135 119 136 If we specify a form, it should use it allowing custom validation to work 120 137 properly. This won't, however, break any of the admin widgets or media.
