Why leave explicit null=True when blank is True in IntegerField, DateField etc?

115 views
Skip to first unread message

Paulo Maciel

unread,
Sep 16, 2015, 6:36:23 PM9/16/15
to Django developers (Contributions to Django itself)
It would be better if IntegerField, DateField, etc did not have to leave explicit null=True when blank is True. 

In my opinion it might look like:

class Abc(models.Model):
    number
= models.IntegerField(blank=True)  # doesn't need leave explicit null=True, it's should be default if blank is True


What do you think?

Enrique Paredes

unread,
Sep 16, 2015, 11:24:05 PM9/16/15
to django-d...@googlegroups.com, Django developers (Contributions to Django itself)
Well, one can call the Zen of python, about just exactly that. explicit is better than implicit.

In this case, explicit becomes a problem for getting used to it, versus implicit that becomes a strange behavior/bug/wtf when you don't expect it.

I'll rather see a ValueError if this is something the model field can't afford (Doesn't do it already?)

Cheers,
E.


Sent from Mailbox


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/7ced3a69-fd04-4ac9-9334-8fde61726810%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yo-Yo Ma

unread,
Sep 17, 2015, 12:14:09 AM9/17/15
to Django developers (Contributions to Django itself)
Another reason you want the two to be separate is that you might allow a field to be blank in forms but then set the value to some context-specific value (vs a simple default=x) before saving.

Tom Christie

unread,
Sep 17, 2015, 9:23:49 AM9/17/15
to Django developers (Contributions to Django itself)
That kind of implicit behavior would just leave things more confused.
Writing a few characters less code isn't a benefit if it comes at the expense of making the behavior less obvious.

Paulo Maciel

unread,
Sep 21, 2015, 6:52:08 PM9/21/15
to Django developers (Contributions to Django itself)
Why confused? It's optional, if the developer wanna put null=True, he could.
I don't think need to be putting null = True, this is redundant. If this is a standard behavior, you need not be explicit.
I think this should be optional, by default these fields should always be null=True implicitly.
Django's philosophy is to simplify.

Tim Graham

unread,
Sep 21, 2015, 8:07:38 PM9/21/15
to Django developers (Contributions to Django itself)
As Yo-Yo mentioned, there are valid use cases for blank=True, null=False, and I believe having one field option implicitly change another actually adds complexity instead of simplifying things.

Shai Berger

unread,
Sep 21, 2015, 9:34:04 PM9/21/15
to django-d...@googlegroups.com
Hi,

(edited a little)

On Tuesday 22 September 2015 03:07:37 Tim Graham wrote:
> On Monday, September 21, 2015 at 6:52:08 PM UTC-4, Paulo Maciel wrote:
> > Why confused? It's optional, if the developer wanna put null=True, he
> > could.
> > I don't think need to be putting null = True, this is redundant. If this
> > is a standard behavior, you need not be explicit.
>
> As Yo-Yo mentioned, there are valid use cases for blank=True, null=False,
> and I believe having one field option implicitly change another actually
> adds complexity instead of simplifying things.
>
Even if we did accept some sort of implication there, it would be the other
way around. "null=True" is a feature of the model field itself, while
"blank=True" only sets the default behavior of form fields generated for it. It
would make some sense for null=True to imply blank=True, but not as you
suggest.

Shai.
Reply all
Reply to author
Forward
0 new messages