Challenge - 5 Problems
Django Model Fields Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Django model field default value?
Consider this Django model field definition:
What will be the value of
age = models.IntegerField(default=20)
What will be the value of
age if a new model instance is created without specifying age?Attempts:
2 left
💡 Hint
Think about what the default parameter does in Django model fields.
✗ Incorrect
The default parameter sets the value automatically if none is provided. Here, age will be 20 if not specified.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a CharField with max length 50 and allows blank values?
You want to define a Django model field that stores text up to 50 characters and can be left blank. Which option is correct?
Attempts:
2 left
💡 Hint
Remember that max_length is required for CharField and blank=True allows empty input.
✗ Incorrect
max_length is mandatory for CharField. blank=True allows form validation to accept empty values.
🔧 Debug
advanced2:00remaining
What error does this model field definition cause?
Examine this Django model field:
What error will this cause when running migrations?
price = models.DecimalField(max_digits=5, decimal_places=2, max_length=10)
What error will this cause when running migrations?
Attempts:
2 left
💡 Hint
Check the valid parameters for DecimalField.
✗ Incorrect
DecimalField does not accept max_length parameter, so it raises a TypeError.
❓ state_output
advanced2:00remaining
What is the value of 'is_active' after saving this model instance?
Given this model field:
And this code:
What will be the value of
is_active = models.BooleanField(default=True)
And this code:
obj = MyModel() obj.is_active = False obj.save()
What will be the value of
is_active in the database?Attempts:
2 left
💡 Hint
Default is only used if no value is assigned.
✗ Incorrect
Explicitly setting is_active to False overrides the default. The saved value is False.
🧠 Conceptual
expert3:00remaining
Which field option combination ensures a unique, non-null email field that can be blank in forms?
You want to define an email field in a Django model that:
- Must be unique in the database
- Cannot be null in the database
- Can be left blank in forms (optional input)
Which option correctly achieves this?
- Must be unique in the database
- Cannot be null in the database
- Can be left blank in forms (optional input)
Which option correctly achieves this?
Attempts:
2 left
💡 Hint
null controls database nullability; blank controls form validation.
✗ Incorrect
null=False means database column cannot be null, blank=True allows empty form input, unique=True enforces uniqueness.