0
0
Djangoframework~10 mins

Defining models with fields in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Django model with a character field named 'title'.

Django
from django.db import models

class Book(models.Model):
    title = models.[1](max_length=100)
Drag options to blanks, or click blank then click option'
ACharField
BIntegerField
CTextField
DDateField
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text data.
Forgetting to set max_length for CharField.
2fill in blank
medium

Complete the code to add a date field named 'published_date' to the model.

Django
class Book(models.Model):
    published_date = models.[1]()
Drag options to blanks, or click blank then click option'
ACharField
BBooleanField
CIntegerField
DDateField
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField for dates.
Using IntegerField for dates.
3fill in blank
hard

Fix the error in the model field definition to store a number of pages as an integer.

Django
class Book(models.Model):
    pages = models.[1]()
Drag options to blanks, or click blank then click option'
ACharField
BIntegerField
CDateField
DTextField
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField with max_length for numbers.
Using max_length with IntegerField.
4fill in blank
hard

Fill both blanks to define a Boolean field named 'is_bestseller' with default False.

Django
class Book(models.Model):
    is_bestseller = models.[1](default=[2])
Drag options to blanks, or click blank then click option'
ABooleanField
BFalse
CTrue
DCharField
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField for Boolean values.
Setting default to True instead of False.
5fill in blank
hard

Fill all three blanks to create a model field 'rating' that stores decimal numbers with max 3 digits and 1 decimal place.

Django
class Book(models.Model):
    rating = models.[1](max_digits=[2], decimal_places=[3])
Drag options to blanks, or click blank then click option'
ADecimalField
B3
C1
DFloatField
Attempts:
3 left
💡 Hint
Common Mistakes
Using FloatField which can cause rounding errors.
Confusing max_digits and decimal_places.