Skip to content

Commit b0a90ec

Browse files
committed
implement value_omitted_from_data function inside widget
1 parent ad7dde3 commit b0a90ec

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

postgres_composite_types/forms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ def value_from_datadict(self, data, files, name):
218218
for subname, widget in self.widgets.items()
219219
}
220220

221+
def value_omitted_from_data(self, data, files, name):
222+
for key in data:
223+
if key.startswith('{}-'.format(name)):
224+
return False
225+
return True
226+
221227
def id_for_label(self, id_):
222228
"""
223229
Wrapper around the field widget's `id_for_label` method.

tests/test_forms.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ def test_null_initial_data(self):
122122
""",
123123
str(form['simple_field']))
124124

125+
def test_value_omission_check_inside_widget(self):
126+
form = self.SimpleForm()
127+
widget = form.fields['simple_field'].widget
128+
self.assertFalse(
129+
widget.value_omitted_from_data(
130+
data=self.simple_valid_data,
131+
files=[],
132+
name='simple_field',
133+
)
134+
)
135+
125136
# pylint:disable=invalid-name
126137
def assertHTMLContains(self, text, content, count=None, msg=None):
127138
"""

0 commit comments

Comments
 (0)