On Tue, May 17, 2011 at 5:45 PM, Greg Donald <gdon...@gmail.com> wrote:
> On Tue, May 17, 2011 at 3:20 PM, Lucian Nicolescu <lucia...@gmail.com> > wrote: > > AFAIK Django does not create SQL instructions for default values. But > > if you specify a default value inside the model field declaration and > > use the orm for inserts it will correctly assign it. > > That's the behavior I expected, but that's not what I get. See the > code I posted. My Form Model complains that my BooleanField type is > missing when I do not supply it explicitly. > > Perhaps if you posted more of your code someone could help. In this thread at any rate all I see is a single line of code that presumably defines the field you are talking about in your model? A model with a field as you have defined it does behave the way you seem to be requesting. Specifically, this model: class BField(models.Model): x = models.BooleanField(default=False) def __unicode__(self): return '%s' % self.x and a bare-bones model form created for it: >>> from ttt.models import BField >>> from django import forms >>> class BForm(forms.ModelForm): ... class Meta: ... model = BField ... when created with an empty data dictionary: >>> bf = BForm({}) ...is reported as valid and has no errors: >>> bf.is_valid() True >>> bf.errors {} ...and successfully saves, creating a model instance with the specified default: >>> BField.objects.all() [] >>> bf.save() <BField: False> >>> BField.objects.all() [<BField: False>] >>> Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.