KEMBAR78
Field Options | PDF
0% found this document useful (0 votes)
22 views1 page

Field Options

The document discusses field options in Django models, including common arguments like null, blank, and choices. null controls if empty values are stored as NULL in the database. blank controls validation and if a field can be empty. choices provides selectable options for a field.

Uploaded by

Andres
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Field Options

The document discusses field options in Django models, including common arguments like null, blank, and choices. null controls if empty values are stored as NULL in the database. blank controls validation and if a field can be empty. choices provides selectable options for a field.

Uploaded by

Andres
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Field options¶

Each field takes a certain set of field-specific arguments (documented in the model field
reference). For example, CharField (and its subclasses) require a max_length argument which
specifies the size of the VARCHAR database field used to store the data.

There’s also a set of common arguments available to all field types. All are optional. They’re
fully explained in the reference, but here’s a quick summary of the most often-used ones:

null
If True, Django will store empty values as NULL in the database. Default is False.

blank

If True, the field is allowed to be blank. Default is False.

Note that this is different than null. null is purely database-related, whereas blank is


validation-related. If a field has blank=True, form validation will allow entry of an empty
value. If a field has blank=False, the field will be required.

choices

A sequence of 2-tuples to use as choices for this field. If this is given, the default form
widget will be a select box instead of the standard text field and will limit choices to the
choices given.

A choices list looks like this:

YEAR_IN_SCHOOL_CHOICES = [

('FR', 'Freshman'),

('SO', 'Sophomore'),

('JR', 'Junior'),

('SR', 'Senior'),

('GR', 'Graduate'),

Note

A new migration is created each time the order of choices changes.

You might also like