0
0
Djangoframework~30 mins

Field types (CharField, IntegerField, DateField) in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Django Model with CharField, IntegerField, and DateField
📖 Scenario: You are building a simple Django app to store information about books in a library. Each book has a title, a number of pages, and a publication date.
🎯 Goal: Create a Django model named Book with three fields: a title using CharField, a pages using IntegerField, and a published_date using DateField.
📋 What You'll Learn
Create a Django model class named Book
Add a title field using CharField with max length 100
Add a pages field using IntegerField
Add a published_date field using DateField
💡 Why This Matters
🌍 Real World
Django models are used to define the structure of data stored in a database for web applications.
💼 Career
Understanding Django field types is essential for backend web development roles using Django framework.
Progress0 / 4 steps
1
Create the Book model class
Create a Django model class called Book that inherits from models.Model.
Django
Need a hint?

Start by defining a class named Book that inherits from models.Model.

2
Add the title field with CharField
Inside the Book model, add a field called title using models.CharField with max_length=100.
Django
Need a hint?

Use models.CharField(max_length=100) to create the title field.

3
Add the pages field with IntegerField
Add a field called pages to the Book model using models.IntegerField().
Django
Need a hint?

Use models.IntegerField() to create the pages field.

4
Add the published_date field with DateField
Add a field called published_date to the Book model using models.DateField().
Django
Need a hint?

Use models.DateField() to create the published_date field.