Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#22145 closed Cleanup/optimization (fixed)

Clarify documentation on Field.blank and Field.null options

Reported by: skipjack@… Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I find the documentation on the 'null' and 'blank' options for model fields do miss one point.

It is clearly stated that 'null' is for the database contraints and 'blank' is for the form validation (less clear though). While there are almost two paragraphs describing the correct setting for allowing empty string values (null=False, blank=True), it is not perfectly clear what setting is needed in order to deal with empty values for the remaining field types.

I missed one sentence like for (almost?) all other field types you need to set both blank and null to True in order to allow for empty values in your model.

Or am I missing something else? (I'm quite new to Django.)

For reference:

Attachments (1)

22145.patch (2.2 KB ) - added by out0fbound 11 years ago.
Clarify documentation on Field.blank and Field.null options

Download all attachments as: .zip

Change History (5)

comment:1 by Daniele Procida, 11 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization
Version: 1.6master

I agree that this could be improved. There's the additional issue in that we say:

Only use null=True for non-string fields

followed by:

Avoid using null on string-based fields such as CharField and TextField unless you have an excellent reason.

which repeats itself, but in an inconsistent way!

by out0fbound, 11 years ago

Attachment: 22145.patch added

Clarify documentation on Field.blank and Field.null options

comment:2 by out0fbound, 11 years ago

Has patch: set

Added patch 22145.patch and created a pull request for this ticket(https://github.com/django/django/pull/2367)

Last edited 11 years ago by out0fbound (previous) (diff)

comment:3 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 3390550f6f645f82354eaffa1d3c89dfa041f1aa:

Fixed #22145 -- Clarified docs on Field.blank and Field.null options.

Thanks skipjack at peru.com for the suggestion.

comment:4 by Tim Graham <timograham@…>, 11 years ago

In f2b513c9e8416855a92e66928c2e22a8fc639273:

[1.6.x] Fixed #22145 -- Clarified docs on Field.blank and Field.null options.

Thanks skipjack at peru.com for the suggestion.

Backport of 3390550f6f from master

Note: See TracTickets for help on using tickets.
Back to Top