0
0
Djangoframework~20 mins

Field types (CharField, IntegerField, DateField) in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Field Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the default max length of a CharField in Django?
Consider the following Django model field:
name = models.CharField()

What will happen when you run migrations?
AIt defaults max_length to 255 automatically
BIt sets max_length to 100 by default
CIt raises a TypeError because max_length is required
DIt allows unlimited length strings
Attempts:
2 left
💡 Hint
Think about what Django requires for CharField length.
state_output
intermediate
1:30remaining
What value is stored in the database for this IntegerField?
Given this model field:
age = models.IntegerField(default=18)

What will be the value of age if you create a new instance without specifying age?
ANone
B18
C0
DRaises an error for missing value
Attempts:
2 left
💡 Hint
Check the default parameter behavior.
📝 Syntax
advanced
2:00remaining
Which option correctly defines a DateField that allows empty values?
You want a DateField that can be empty in the database and in forms. Which is correct?
Abirth_date = models.DateField()
Bbirth_date = models.DateField(blank=True)
Cbirth_date = models.DateField(null=True)
Dbirth_date = models.DateField(blank=True, null=True)
Attempts:
2 left
💡 Hint
Remember the difference between blank and null in Django fields.
🔧 Debug
advanced
2:00remaining
Why does this model raise an error on migration?
Model code:
class Person(models.Model):
    name = models.CharField(max_length=50)
    age = models.IntegerField(blank=True)

What is the cause of the error?
AIntegerField cannot have blank=True without null=True
BCharField max_length must be greater than 50
CMissing default value for age field
DModels must have a primary key defined explicitly
Attempts:
2 left
💡 Hint
Check the meaning of blank and null for IntegerField.
🧠 Conceptual
expert
2:30remaining
How does Django handle DateField input from forms when blank=True and null=True are set?
If a DateField has blank=True and null=True, what happens when a user submits an empty date in a form?
AThe field stores NULL in the database and passes validation
BThe field stores an empty string in the database
CThe form raises a validation error for empty input
DThe field stores the current date automatically
Attempts:
2 left
💡 Hint
Think about how blank and null affect form and database behavior.