Django

Django Models - Basics

Model fields, field types, Meta class, model methods, QuerySet basics, migrations

22 câu hỏi phỏng vấn·
Junior
1

What is a Model in Django?

Câu trả lời

A Django Model is a Python class that represents a table in the database. Each Model attribute corresponds to a column in the table. Django uses ORM (Object-Relational Mapping) to automatically translate operations on Python objects into SQL queries, allowing database manipulation without writing SQL directly.

2

Which base class should be used to create a Django Model?

Câu trả lời

All Django Models must inherit from django.db.models.Model. This base class provides all the necessary functionality to interact with the database: table creation, queries, saving, deletion, etc. Without this inheritance, the class would not be recognized as a Model by Django.

3

Which field type should be used to store a string with a limited length?

Câu trả lời

CharField is used to store short to medium strings with a maximum length defined via max_length. This parameter is required for CharField. For longer texts without size limits, TextField should be used instead as it has no length restriction.

4

What is the difference between the null and blank options in a Django field?

5

How to define a default value for a Model field?

+19 câu hỏi phỏng vấn

Nắm vững Django cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí