diff --git a/django/forms/forms.py b/django/forms/forms.py --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -502,6 +502,11 @@ return self.field.widget.is_hidden is_hidden = property(_is_hidden) + def _required(self): + "Returns True if this BoundField's field is required." + return self.field.required + required = property(_required) + def _auto_id(self): """ Calculates and returns the ID attribute for this BoundField, if the diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py --- a/tests/regressiontests/forms/forms.py +++ b/tests/regressiontests/forms/forms.py @@ -1739,6 +1739,17 @@ +Use form.[field].required to identify required fields. +>>> class OptionalPersonForm(Form): +... first_name = CharField() +... last_name = CharField() +... nick_name = CharField(required=False) +>>> t = Template('
') +>>> for boundfield in OptionalPersonForm(auto_id=False): +... print t.render(Context({'field': boundfield})) + + + # The empty_permitted attribute ##############################################