Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#22145 closed Cleanup/optimization (fixed)

Clarify documentation on Field.blank and Field.null options

Reported by: skipjack@… Owned by: nobody
Component: Documentation Version: master
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 12 months ago.
Clarify documentation on Field.blank and Field.null options

Download all attachments as: .zip

Change History (5)

comment:1 Changed 12 months ago by EvilDMP

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization
  • Version changed from 1.6 to master

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!

Changed 12 months ago by out0fbound

Clarify documentation on Field.blank and Field.null options

comment:2 Changed 12 months ago by out0fbound

  • Has patch set

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

Last edited 12 months ago by out0fbound (previous) (diff)

comment:3 Changed 12 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 3390550f6f645f82354eaffa1d3c89dfa041f1aa:

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

Thanks skipjack at peru.com for the suggestion.

comment:4 Changed 12 months ago by Tim Graham <timograham@…>

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