June 15, 2025
What are models in Django
Models are very important in Django. We perform database related operation by using model classes. In Django we use ORM (object relational mapper) for performing database operation, one model class represent to one database table and each property of model class represent to table column. Views interact with model classes to retrieve and save data into database. We can also define relations among tables using Django model classes, few types of relations are one to one, one to many and many to many. Example of model class is mentioned below:
Model Class Sample
#student.py # model class
from django.db import models
class Student(models.Model):
name = models.CharField(max_length=100)
class = models.DecimalField(max_digits=8, decimal_places=2)
roll_no = models.CharField(max_length=100)
created_at = models.DateTimeField(auto_now_add=True)