Wednesday, August 26, 2015

Re: ForeignKey Fields null=True does not imply blank=True

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJV3aYCAAoJEH2EY3tf/UcFMyQQAKMzIPjm5+s/kd5YLtLte0gX
D/DvBdj1hyJOs3HiOwvyfWYfhK7swfxZW07Ji62aYwL8DgWQ8LgAk/fs/IlmvsiM
lGzLYzhn8j2QGTKUI84txc4NuhnwZrhWVMxgmuyse6xofQzsvUlWgNLaDimBUW6a
7Hv6atXtDA6PuD+fSmYcWkkoo+r62WoV5/2nOYdadkWaMGddt6byAY0ZLR5gLbcL
0N9Z8hZ0nvGRofxO7JEDhsZ47uk62eL3PlMGapfWl2RW3PSOuqTuYqNDmPvYkti6
ZQsKCPd9U4DoWbIVCJBZ/WBHMy9BIZDpT7fn4gFeXVpgvxyD5+M19W1377GbXC6B
NB+SBrMrKYzoBMDOjkYkUFH9LaHhr7u3UygYT8s0aoO8C+FZVCXLxTSyAZmj4O5e
/892/Hf2xUCstQcOb1c4VBM1Z/XZRY3WUX9uT3ycC44VBl1ZEvrPXGJ9tJMRGi4w
fPWmXwXTI0An5sxh67fWsOCYNZ/ARRTOVXHvIA7dhG3JLsllaigUdIGUqBThBxRD
EgkHAqcKXh9ZE5xAcFR2YSkXTHrRPr/lH8jmzGp/a3My2cxw0TM61+DNRjirbh1r
Q/u8t0dCBB2eE3Hs4uTq4GDpvPrcjWgb5MKS9qzLJ6sNv789WXO10K538kz2Tkke
v/ggAxwWV7dtsGuMBJ/e
=MNJ3
-----END PGP SIGNATURE-----
On 26/08/15 11:59, khoobks wrote:
> I just discovered some interesting behaviour in Django 1.8.4 and was
> wondering if this was an unexpected side effect or specifically designed
> behaviour.

That behaviour is intended and documented[0].

blank and null working on completely different levels.
blank is only for validation in the django code.
null affects the database field.

It's useful if you like to force the user to input something in a field,
but at the same time you have to initialise a model with null at some
other place in your code.
e.g you are importing email addresses, but don't have names in your
current data. You can now easily force the user to set his/her name when
changing settings, without overwriting fields in a form.

regards,
Florian

[0] https://docs.djangoproject.com/en/1.8/ref/models/fields/#null

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55DDA5FB.3080600%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment