| 1340 | return self.to_python(value) |
| 1341 | |
| 1342 | def formfield(self, **kwargs): |
| 1343 | # Passing max_length to forms.CharField means that the value's length |
| 1344 | # will be validated twice. This is considered acceptable since we want |
| 1345 | # the value in the form field (to pass into widget for example). |
| 1346 | defaults = {"max_length": self.max_length} |
| 1347 | # TODO: Handle multiple backends with different feature flags. |
| 1348 | if self.null and not connection.features.interprets_empty_strings_as_nulls: |
| 1349 | defaults["empty_value"] = None |
| 1350 | defaults.update(kwargs) |
| 1351 | return super().formfield(**defaults) |
| 1352 | |
| 1353 | def deconstruct(self): |
| 1354 | name, path, args, kwargs = super().deconstruct() |