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
course content

Зміст курсу

Django ORM Ninja: Advanced Techniques for Developers

Django ORM Ninja: Advanced Techniques for Developers

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 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?

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

Виберіть правильну відповідь

Which of the following is a required argument for CharField?

Which of the following is a required argument for CharField?

Виберіть правильну відповідь

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

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

Виберіть правильну відповідь

The choices option in a Django model field:

The choices option in a Django model field:

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 2
some-alt