summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2010-03-31 08:08:29 +0000
committerBrian Rosner <brosner@gmail.com>2010-03-31 08:08:29 +0000
commit64e4ffc932c78e6ccd66f20d5d74083fda3a3915 (patch)
tree13639aeff75eedce36012eaec9734427b557c671 /tests
parent2613872969f52815859bad9533104b47b63d6375 (diff)
[1.1.X] Restored pre-r10062 behavior allowing None from formfield_callback to exclude itself from the form
Backported from r12891 from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12892 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/model_forms/models.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 92e05e19ef..b20d5dd8c9 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -205,6 +205,22 @@ class Post(models.Model):
def __unicode__(self):
return self.name
+class MarkupField(models.CharField):
+ def __init__(self, *args, **kwargs):
+ kwargs["max_length"] = 20
+ super(MarkupField, self).__init__(*args, **kwargs)
+
+ def formfield(self, **kwargs):
+ # don't allow this field to be used in form (real use-case might be
+ # that you know the markup will always be X, but it is among an app
+ # that allows the user to say it could be something else)
+ # regressed at r10062
+ return None
+
+class CustomFieldForExclusionModel(models.Model):
+ name = models.CharField(max_length=10)
+ markup = MarkupField()
+
__test__ = {'API_TESTS': """
>>> from django import forms
>>> from django.forms.models import ModelForm, model_to_dict
@@ -1547,6 +1563,19 @@ False
>>> f.is_valid()
True
+# Model field that returns None to exclude itself with explicit fields ########
+
+>>> class CustomFieldForExclusionForm(ModelForm):
+... class Meta:
+... model = CustomFieldForExclusionModel
+... fields = ['name', 'markup']
+
+>>> CustomFieldForExclusionForm.base_fields.keys()
+['name']
+
+>>> print CustomFieldForExclusionForm()
+<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="10" /></td></tr>
+
# Clean up
>>> import shutil
>>> shutil.rmtree(temp_storage_dir)