#27039: ModelFields with 'default' value set and 'required'=False in form does
not
use default value
----------------------------+--------------------------------------------
Reporter: devbis | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.10
Severity: Normal | Keywords: default non-required modelform
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------------
I have Model M with corresponding ModelForm
{{{
class M(models.Model):
f = models.CharField(max_length=255, default=u'default_value')
class MF(forms.ModelForm):
class Meta:
model = M
fields = ['f']
f = forms.CharField(required=False)
}}}
I save form with empty data, expecting receive default value in field
{{{
mf = MF({})
if mf.is_valid():
m = mf.save(commit=False)
m.f
>>> u''
}}}
expected behavior
{{{
m.f
>>> u'default_value'
}}}
Commits, that broke previous behavior:
https://github.com/django/django/commit/375e1cfe2b2e1c3c57f882147c34902c6e8189ac
Offered patch:
{{{
--- django/forms/models.py (revision
35225e2ade08ea32e36a994cd4ff90842c599e20)
+++ django/forms/models.py (revision )
@@ -385,7 +385,7 @@
exclude.append(name)
try:
- self.instance = construct_instance(self, self.instance,
opts.fields, opts.exclude)
+ self.instance = construct_instance(self, self.instance,
opts.fields, exclude)
except ValidationError as e:
self._update_errors(e)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27039>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.75bb6458063524a12481da38a0a22504%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.