0
0
Djangoframework~20 mins

User model overview in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
User Model Overview in Django
📖 Scenario: You are building a simple Django app that manages users. You want to understand how to create and configure a basic user model to store user information.
🎯 Goal: Build a basic Django user model with fields for username, email, and date joined.
📋 What You'll Learn
Create a Django model named User
Add fields username, email, and date_joined with correct field types
Set username as a unique field
Use Django's models.Model as the base class
💡 Why This Matters
🌍 Real World
User models are essential in web apps to store and manage user data like login info and profiles.
💼 Career
Understanding Django models is key for backend web development roles working with Python and Django frameworks.
Progress0 / 4 steps
1
Create the User model class
Create a Django model class called User that inherits from models.Model.
Django
Need a hint?

Use class User(models.Model): to start your model.

2
Add username and email fields
Inside the User model, add a username field as models.CharField with max_length=150 and unique=True. Also add an email field as models.EmailField.
Django
Need a hint?

Use models.CharField for username with max_length=150 and unique=True. Use models.EmailField for email.

3
Add date_joined field
Add a date_joined field to the User model using models.DateTimeField with auto_now_add=True to store when the user joined.
Django
Need a hint?

Use models.DateTimeField(auto_now_add=True) to automatically set the join date.

4
Add string representation method
Add a __str__ method to the User model that returns the username as a string.
Django
Need a hint?

Define def __str__(self): and return self.username.