0
0
Djangoframework~5 mins

Model Meta class options in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the <code>Meta</code> class inside a Django model?
The <code>Meta</code> class is used to configure model behavior like database table name, ordering, verbose names, and other options without adding fields.
Click to reveal answer
beginner
What does the <code>ordering</code> option in a Django model's <code>Meta</code> class do?
It defines the default order in which records are returned from the database, e.g., ordering = ['name'] sorts by the 'name' field ascending.
Click to reveal answer
beginner
How do you change the database table name for a Django model?
Use the db_table option inside the Meta class, e.g., db_table = 'custom_table_name'.
Click to reveal answer
intermediate
What is the use of verbose_name and verbose_name_plural in Django model Meta?
verbose_name sets a human-friendly singular name for the model, and verbose_name_plural sets the plural form. These appear in admin and messages.
Click to reveal answer
intermediate
What does setting <code>unique_together</code> in a Django model's <code>Meta</code> class do?
It enforces that a combination of two or more fields must be unique together in the database, preventing duplicate pairs.
Click to reveal answer
Which Meta option changes the default database table name for a Django model?
Atable_name
Bdb_table
Cdatabase_name
Dtable
What does the ordering option in a Django model's Meta class control?
AThe order of records returned from queries
BThe order of migrations
CThe order of models in admin
DThe order of fields in the model
If you want to make sure two fields together are unique in a Django model, which Meta option do you use?
Aunique_fields
Bunique_combo
Cunique_together
Dunique_pair
Which Meta option sets a human-friendly singular name for a Django model?
Amodel_name
Bfriendly_name
Cdisplay_name
Dverbose_name
What happens if you do NOT define a Meta class in a Django model?
ADefault options are used, like table name and ordering
BThe model will not work
CYou must define it or get an error
DThe model will be abstract
Explain how the Meta class in a Django model helps customize the model's behavior.
Think about how you can change names, order, and uniqueness without adding fields.
You got /3 concepts.
    Describe the difference between verbose_name and verbose_name_plural in Django model Meta options.
    Consider how words change when talking about one item versus many.
    You got /3 concepts.