Setting "blank" to one Field?

10 views
Skip to first unread message

Xan

unread,
Sep 14, 2007, 2:41:21 PM9/14/07
to Django users
Hi,

Following the database API reference (http://www.djangoproject.com/
documentation/db-api/):

If a ForeignKey field has null=True set (i.e., it allows
NULL values), you can assign None to it. Example:

e = Entry.objects.get(id=2)
e.blog = None
e.save() # "UPDATE blog_entry SET blog_id = NULL ...;"

I want to know what is equivalent to Blank? That is, how to set
e.blog to blank if blank=True?

Thanks,
Xan.

r_f_d

unread,
Sep 14, 2007, 9:34:19 PM9/14/07
to Django users
I am not sure this is possible, null=True is for the database, while
blank=True is for form validation. Also there is a datatype None,
there is no datatype blank. If you tried to assign blank as apposed
to 'blank' to any variable within python it would complain. If there
were not a named variable called blank it would tell you that 'blank
is not defined', whilst it is easily accomplished to set something to
None. Django is written in python and while it does some really cool
things easily, it has not implemented a class called blank, afaik.
-richard

Collin Grady

unread,
Sep 15, 2007, 6:33:52 PM9/15/07
to Django users
There is no such thing as blank, especially on a ForeignKey.

blank=True has absolutely nothing to do with the database, as the
documentation for it clearly states :)

It merely makes it so you can give it no value in form validation,
like in admin.

Xan

unread,
Sep 16, 2007, 4:49:01 AM9/16/07
to Django users
I suppose that it were exists. Because if we put no value in the
database in one ForeignKey (in admin mode), then we could revert the
value to blank. Internally I don't know how store blank values (if
null is not True), but I think that it could be set someway

Well, thanks,
I will change all my blank=True for null=True

Thanks a lot,
Xan.

ringemup

unread,
Sep 16, 2007, 11:26:57 AM9/16/07
to Django users
Shouldn't the empty string be equivalent to blank?

Collin Grady

unread,
Sep 16, 2007, 9:08:33 PM9/16/07
to Django users
You've misunderstood - you need blank=True /and/ null=True.

blank=True will tell admin to let you pick nothing for it, and
null=True will then allow the NULL value to be entered.

NULL is what you use to signify "unset" on a ForeignKey

Reply all
Reply to author
Forward
0 new messages