Articles → DJANGO → Create Your First Model In Django
Create Your First Model In Django
Steps Of Creating The Model
- Create a new module using the following command
<python_path>\python manage.py startapp <module_name>
- In the module, add the following code in models.py
from django.db import models
# Create your models here.
class MyNewScreen(models.Model):
name = models.CharField(max_length = 120)
def __str__(self):
return self.name
- In the root folder, add the module in settings.py
Click to Enlarge
- Inside the module, add following code in admin.py
from django.contrib import admin
# Register your models here.
from .models import MyNewScreen
admin.site.register(MyNewScreen)
- In the command prompt, execute the following command
<python path>\python manage.py makemigrations
<python path>\python manage.py migrate
Output
Click to Enlarge
Click to Enlarge