#13824: ModelValidation ignores blank=True
---------------------------+------------------------------------------------
 Reporter:  anonymous      |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Documentation  |     Version:  1.2       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 Cheers,

 I'm not quite sure if this is a feature or a bug, so sorry if i
 misunderstood this.

 I am using a Model "Foo" that has a field like this:

 {{{
 #!python
 [...]
 class Foo(models.Model):
     uid = models.ForeignKey(UserProfile, blank=True)
 [...]
 }}}

 Next, I'm using this Model in a Form (via !ModelForm):
 {{{
 #!python
 class FooForm(ModelForm):

     class Meta:
         model = Foo
 [...]
 }}}

 I expect Django to ignore the `uid` when calling `is_valid()`, as it's
 `blank` attribute is set `True` , but I get a !ValueError:
 {{{
 #!sh
 ValueError at /foo/add/

 Cannot assign None: "Foo.uid" does not allow null values.

 Request Method:         POST
 Request URL:    http://localhost:8000/de/foo/add/
 Django Version:         1.2.1
 Exception Type:         ValueError
 Exception Value:

 Cannot assign None: "Foo.uid" does not allow null values.

 Exception Location:     <cut>/lib/python2.6/site-
 packages/django/db/models/fields/related.py in __set__, line 314
 }}}

 This is since at the point where `is_valid()` is valled, uid is set to
 `None`, since it is not sent by the form but filled in my view (it's
 request.user.get_profile().user_id).

 I looked for this in the Django docs, but didn't get a proper solution but
 using `full_clean()` which would need me to adapt the code & use
 try/except .

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13824>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to