Wednesday, August 26, 2015

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

That makes sense however I would have expected the ModelForm to give an error indicating that the foreign key is blank (when it should not be) instead of adding it to the exclusion list meaning that it never gets updated when you call save.



On Wednesday, 26 August 2015 19:43:16 UTC+8, Florian Schweikert wrote:
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/fda4148a-e5fb-482c-9c9d-e1f17a782ba3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment