126 | | |
| 126 | |
| 127 | # Using a tuple for `exclude`. |
| 128 | |
| 129 | >>> class BandAdmin(ModelAdmin): |
| 130 | ... exclude = ('bio',) |
| 131 | >>> ma = BandAdmin(Band, site) |
| 132 | >>> ma.get_form(request).base_fields.keys() |
| 133 | ['name', 'sign_date'] |
| 134 | |
| 135 | # Combining `exclude` tuple on the class and `exclude` list as get_form parameter. |
| 136 | |
| 137 | >>> class BandAdmin(ModelAdmin): |
| 138 | ... exclude = ('bio',) |
| 139 | >>> ma = BandAdmin(Band, site) |
| 140 | >>> ma.get_form(request, exclude=['sign_date']).base_fields.keys() |
| 141 | ['name'] |
| 142 | |
| 143 | # Combining `exclude` tuple on the class and `exclude` tuple as get_form parameter. |
| 144 | |
| 145 | >>> class BandAdmin(ModelAdmin): |
| 146 | ... exclude = ('bio',) |
| 147 | >>> ma = BandAdmin(Band, site) |
| 148 | >>> ma.get_form(request, exclude=('sign_date',)).base_fields.keys() |
| 149 | ['name'] |
| 150 | |
| 160 | # Using `exclude` on an inline admin. |
| 161 | |
| 162 | >>> class ConcertAdmin(StackedInline): |
| 163 | ... model = Concert |
| 164 | ... fk_name = 'main_band' |
| 165 | ... exclude = ['transport'] |
| 166 | >>> ma = ConcertAdmin(Band, site) |
| 167 | >>> ma.get_formset(request).form.base_fields.keys() |
| 168 | ['opening_band', 'day'] |
| 169 | |
| 170 | # Using a tuple for `exclude` on an inline admin. |
| 171 | |
| 172 | >>> class ConcertAdmin(StackedInline): |
| 173 | ... model = Concert |
| 174 | ... fk_name = 'main_band' |
| 175 | ... exclude = ('transport',) |
| 176 | >>> ma = ConcertAdmin(Band, site) |
| 177 | >>> ma.get_formset(request).form.base_fields.keys() |
| 178 | ['opening_band', 'day'] |
| 179 | |
| 180 | # Combining `exclude` tuple on the class and `exclude` list as get_form parameter on inline. |
| 181 | |
| 182 | >>> class ConcertAdmin(StackedInline): |
| 183 | ... model = Concert |
| 184 | ... fk_name = 'main_band' |
| 185 | ... exclude = ['transport'] |
| 186 | >>> ma = ConcertAdmin(Band, site) |
| 187 | >>> ma.get_formset(request, exclude=['opening_band']).form.base_fields.keys() |
| 188 | ['day'] |
| 189 | |
| 190 | # Combining `exclude` tuple on the class and `exclude` tuple as get_form parameter on inline. |
| 191 | |
| 192 | >>> class ConcertAdmin(StackedInline): |
| 193 | ... model = Concert |
| 194 | ... fk_name = 'main_band' |
| 195 | ... exclude = ['transport'] |
| 196 | >>> ma = ConcertAdmin(Band, site) |
| 197 | >>> ma.get_formset(request, exclude=('opening_band',)).form.base_fields.keys() |
| 198 | ['day'] |
| 199 | |
| 200 | # Using `fields` and `exclude` on inline. |
| 201 | |
| 202 | >>> class ConcertAdmin(StackedInline): |
| 203 | ... model = Concert |
| 204 | ... fk_name = 'main_band' |
| 205 | ... fields = ['opening_band', 'transport'] |
| 206 | ... exclude = ['transport'] |
| 207 | >>> ma = ConcertAdmin(Band, site) |
| 208 | >>> ma.get_formset(request).form.base_fields.keys() |
| 209 | ['opening_band'] |
| 210 | |