Django Models are stored in Models are basically the database structure of the application.

Following is the code of Django model:

from django.db import models

# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(max_length=100, unique=True)
    body = models.TextField()
    posted = models.DateTimeField(db_index=True, auto_now_add=True)
    category = models.ForeignKey('gbs_blog.Category')

class Category(models.Model):
    title = models.CharField(max_length=100, db_index=True)
    slug = models.SlugField(max_length=100, db_index=True)

In Above code , Post and Category are the database tables and title, slug ,body, posted are the columns/fields of database tables.

Next >> Django Tutorial : Querying Data From Models (

Leave a Reply

Your email address will not be published. Required fields are marked *