Thursday, May 20, 2021

How to Create Django Models

 How create Django Models


Django Models:
    Django Models is method used to create database.One class contains one database table.

Go to models.py
from django.db import models

class BlogModel(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    
    def __str__(self):
        return self.title
    Everything before use need to import package
    BlogModel is choosable name.What ever name your want will give that.Then send Model argument to that class.
    Inside of the class i define two fields.One is the title another one is a content.
    Django models return a objects .So we need to convert objects to string.
Thank you.Happy coding!


Previous Post
Next Post

0 Comments: