Thursday, June 24, 2010

null=False, blank=True and errors saving in admin?

Upgrading from Django 1.0 to 1.2, I'm suddenly getting errors when
creating objects in the admin form a class that essentially looks like
this:

class MyObject(models.Model):
name = models.CharField(max_length=50)
other_thing = models.ForeignKey(MyOtherModel, null=False,
blank=True)

def save(self, *args, **kwargs):
logging.debug('saving here')
if not self.other_thing:
other_thing = MyOtherModel()
other_thing.save()
self.other_thing = other_thing
super(MyObject, self).save(*args, **kwargs)

Creating a MyObject in the admin and leaving the other_thing field
blank results in the following error:

Cannot assign None: "MyObject.other_thing" does not allow null values.

The logging statement is never being hit, so it looks like the over-
aggressive validation is being performed in the ModelForm. What am I
doing wrong?

Thanks!

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate