Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Field Data Types | Models, datatypes, and fields
Django ORM Ninja: Advanced Techniques for Developers

Field Data TypesField Data Types

In this chapter, we will consider the most useful data types for fields, with other types described in the official documentation.

Field data typePython typeDescription
CharFieldstrText-based values
IntegerFieldintPositive and negative integer field
TextFieldstrA large text field without any limitations in character number.
DecimalFieldfloat (decimal)It is a fixed-precision decimal number. More precise than just float numbers in Python. This field typically includes parameters like max_digits and decimal_places
DateFielddateA date, presented as datetime.date instance in Python
DateTimeFielddatetimeA date and time, presented as datetime.datetime instance in Python
EmailFieldstrString that checks that value is a valid email address.
ImageField...Validates that the uploaded object is a valid image.

The most common field options are:

  • max_length (it is the required argument for the CharField field);
  • null (if True, it will be possible to store empty values as NULL. Default is False);
  • blank (if True, the field is allowed to be blank. Default is False);
  • default (You can pass the default value for the field. For example, often used date_created = models.DateTimeField(default=datetime.utcnow()) the current time will be stored as a value);
  • primary_key (usually used for the id field);
  • unique (if True, this field must be unique throughout the table. Useful for nickname field, for example);
  • choices (the default form widget will be a select box instead of a standard text field and will limit choices).

Here is an example of how to use the choices field:

1. Which field data type is best for storing a large text without limitations on character number?
2. Which of the following is a required argument for CharField?
3. What does the 'primary_key' option in a Django model field signify?
4. The choices option in a Django model field:

Which field data type is best for storing a large text without limitations on character number?

Select the correct answer

Which of the following is a required argument for CharField?

Select the correct answer

What does the 'primary_key' option in a Django model field signify?

Select the correct answer

The choices option in a Django model field:

Select the correct answer

Everything was clear?

Section 2. Chapter 2
course content

Course Content

Django ORM Ninja: Advanced Techniques for Developers

Field Data TypesField Data Types

In this chapter, we will consider the most useful data types for fields, with other types described in the official documentation.

Field data typePython typeDescription
CharFieldstrText-based values
IntegerFieldintPositive and negative integer field
TextFieldstrA large text field without any limitations in character number.
DecimalFieldfloat (decimal)It is a fixed-precision decimal number. More precise than just float numbers in Python. This field typically includes parameters like max_digits and decimal_places
DateFielddateA date, presented as datetime.date instance in Python
DateTimeFielddatetimeA date and time, presented as datetime.datetime instance in Python
EmailFieldstrString that checks that value is a valid email address.
ImageField...Validates that the uploaded object is a valid image.

The most common field options are:

  • max_length (it is the required argument for the CharField field);
  • null (if True, it will be possible to store empty values as NULL. Default is False);
  • blank (if True, the field is allowed to be blank. Default is False);
  • default (You can pass the default value for the field. For example, often used date_created = models.DateTimeField(default=datetime.utcnow()) the current time will be stored as a value);
  • primary_key (usually used for the id field);
  • unique (if True, this field must be unique throughout the table. Useful for nickname field, for example);
  • choices (the default form widget will be a select box instead of a standard text field and will limit choices).

Here is an example of how to use the choices field:

1. Which field data type is best for storing a large text without limitations on character number?
2. Which of the following is a required argument for CharField?
3. What does the 'primary_key' option in a Django model field signify?
4. The choices option in a Django model field:

Which field data type is best for storing a large text without limitations on character number?

Select the correct answer

Which of the following is a required argument for CharField?

Select the correct answer

What does the 'primary_key' option in a Django model field signify?

Select the correct answer

The choices option in a Django model field:

Select the correct answer

Everything was clear?

Section 2. Chapter 2
some-alt