filmov
tv
create a blog application in django using python | Create Django Models
Показать описание
#create #a #blog #application #in #django #using #python 2nd part #how #make #django #cms #using #html #css #javascript #bootstrap
#fixed #header #on #django #templates #inheritence #create #models #on #django
Step : Fixed our Header in django using python framework.
Step : Create Blog Models
python
Copy code
User = get_user_model()
class Author(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_pic = models.ImageField()
def __str__(self):
class Category(models.Model):
title = models.CharField(max_length=20)
def __str__(self):
class Post(models.Model):
title = models.CharField(max_length=100)
excerpt = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
comment_count = models.IntegerField(default=0)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
thumbnail = models.ImageField()
categories = models.ManyToManyField(Category)
featured = models.BooleanField()
def __str__(self):
Step : Create and Apply Migrations
Generate and apply migrations to create the database tables for your models:
bash
Copy code
Step : Create Admin Interface
python
Copy code
from .models import Author, Category, Post
# Register your models here.
Step : Create Views and Templates
Step : Configure URLs
Step : Create Templates
Create HTML templates for your blog views in the blogapp/templates/blogapp directory. You'll need templates for listing posts, displaying individual posts, and creating/editing posts.
Step : Implement User Authentication
If you want to allow user registration and management, you can use Django's built-in authentication system or third-party packages like Django Allauth.
Thank You for Follow our content.
#fixed #header #on #django #templates #inheritence #create #models #on #django
Step : Fixed our Header in django using python framework.
Step : Create Blog Models
python
Copy code
User = get_user_model()
class Author(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_pic = models.ImageField()
def __str__(self):
class Category(models.Model):
title = models.CharField(max_length=20)
def __str__(self):
class Post(models.Model):
title = models.CharField(max_length=100)
excerpt = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
comment_count = models.IntegerField(default=0)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
thumbnail = models.ImageField()
categories = models.ManyToManyField(Category)
featured = models.BooleanField()
def __str__(self):
Step : Create and Apply Migrations
Generate and apply migrations to create the database tables for your models:
bash
Copy code
Step : Create Admin Interface
python
Copy code
from .models import Author, Category, Post
# Register your models here.
Step : Create Views and Templates
Step : Configure URLs
Step : Create Templates
Create HTML templates for your blog views in the blogapp/templates/blogapp directory. You'll need templates for listing posts, displaying individual posts, and creating/editing posts.
Step : Implement User Authentication
If you want to allow user registration and management, you can use Django's built-in authentication system or third-party packages like Django Allauth.
Thank You for Follow our content.
Комментарии