Thursday, June 24, 2010

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

On Thu, Jun 24, 2010 at 5:40 PM, ringemup <ringemup@gmail.com> wrote:
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.

There is a ticket open on this: http://code.djangoproject.com/ticket/13776

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

No comments:

Post a Comment