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

bookField Data Types

Deslize para mostrar o menu

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:

question mark

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

Select the correct answer

question mark

Which of the following is a required argument for CharField?

Select the correct answer

question mark

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

Select the correct answer

question mark

The choices option in a Django model field:

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Seção 2. Capítulo 2
some-alt