From 6c15b5db6014a7dadb0c237e689bdaed4761fb16 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Wed, 22 Apr 2009 15:48:51 +0000 Subject: Fixed #10208: `ModelAdmin` now respects the `exclude` and `field` atributes of custom `ModelForm`s. Thanks, Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10619 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/modeladmin/models.py | 42 +++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'tests/regressiontests/modeladmin') diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py index 3a7d3f031f..ef05b5a048 100644 --- a/tests/regressiontests/modeladmin/models.py +++ b/tests/regressiontests/modeladmin/models.py @@ -37,7 +37,7 @@ class ValidationTestInlineModel(models.Model): __test__ = {'API_TESTS': """ ->>> from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL +>>> from django.contrib.admin.options import ModelAdmin, TabularInline, HORIZONTAL, VERTICAL >>> from django.contrib.admin.sites import AdminSite None of the following tests really depend on the content of the request, so @@ -262,6 +262,46 @@ blank=True for the model field. Finally, the widget should have the >>> list(cmafa.base_fields['transport'].widget.choices) [('', u'None'), (1, 'Plane'), (2, 'Train'), (3, 'Bus')] +>>> class AdminConcertForm(forms.ModelForm): +... class Meta: +... model = Concert +... exclude = ('transport',) + +>>> class ConcertAdmin(ModelAdmin): +... form = AdminConcertForm + +>>> ma = ConcertAdmin(Concert, site) +>>> ma.get_form(request).base_fields.keys() +['main_band', 'opening_band', 'day'] + +>>> class AdminConcertForm(forms.ModelForm): +... extra = forms.CharField() +... class Meta: +... model = Concert +... fields = ['extra', 'transport'] + +>>> class ConcertAdmin(ModelAdmin): +... form = AdminConcertForm + +>>> ma = ConcertAdmin(Concert, site) +>>> ma.get_form(request).base_fields.keys() +['extra', 'transport'] + +>>> class ConcertInline(TabularInline): +... form = AdminConcertForm +... model = Concert +... fk_name = 'main_band' + +>>> class BandAdmin(ModelAdmin): +... inlines = [ +... ConcertInline +... ] + +>>> ma = BandAdmin(Band, site) +>>> list(ma.get_formsets(request))[0]().forms[0].fields.keys() +['extra', 'transport', 'id', 'DELETE', 'main_band'] + + >>> band.delete() # ModelAdmin Option Validation ################################################ -- cgit v1.3