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: Técnicas Avanzadas para Desarrolladores
course content

Contenido del Curso

Django ORM Ninja: Técnicas Avanzadas para Desarrolladores

Django ORM Ninja: Técnicas Avanzadas para Desarrolladores

1. Introduction to Django ORM
2. Models, datatypes, and fields
3. Queries
4. Relations
5. Complex Queries
6. Advanced

bookField 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 how to use the choices field:

1. ¿Qué tipo de dato de campo es mejor para almacenar un texto grande sin limitaciones en el número de caracteres?
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:
¿Qué tipo de dato de campo es mejor para almacenar un texto grande sin limitaciones en el número de caracteres?

¿Qué tipo de dato de campo es mejor para almacenar un texto grande sin limitaciones en el número de caracteres?

Selecciona la respuesta correcta

Which of the following is a required argument for CharField?

Which of the following is a required argument for CharField?

Selecciona la respuesta correcta

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

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

Selecciona la respuesta correcta

The choices option in a Django model field:

The choices option in a Django model field:

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
some-alt