1. 程式人生 > >Django——博客項目

Django——博客項目

.com efault eat 目標 開發 ctu closed 詳情 module

博客項目

目前的目標是構建一個基於Django的前後端完整的博客系統,首先對項目流程整理如下:

技術分享圖片

1. 分析需求

1.1. 1.基於用戶認證組件和Ajax實現登錄驗證

1.2. 基於forms組件和Ajax實現註冊功能

1.3. 設計系統首頁(文章列表渲染)

1.4. 設計個人站點頁面

1.5. 文章詳情頁

1.6. 實現文章點贊功能

1.7. 實現文章的評論

  1.7.1. 文章的評論

  1.7.2. 評論的評論

1.8. 富文本編輯框和防止xss攻擊

2. 設計表結構

技術分享圖片

module代碼:

技術分享圖片
from django.db import models

# Create your models here. from django.contrib.auth.models import AbstractUser class UserInfo(AbstractUser): """ 用戶信息 """ nid = models.AutoField(primary_key=True) telephone = models.CharField(max_length=11, null=True, unique=True) avatar = models.FileField(upload_to=
avatars/, default="avatars/default.png") create_time = models.DateTimeField(verbose_name=創建時間, auto_now_add=True) blog = models.OneToOneField(to=Blog, to_field=nid, null=True, on_delete=models.CASCADE) def __str__(self): return self.username class Blog(models.Model):
""" 博客信息 """ nid = models.AutoField(primary_key=True) title = models.CharField(verbose_name=個人博客標題, max_length=64) site_name = models.CharField(verbose_name=站點名稱, max_length=64) theme = models.CharField(verbose_name=博客主題, max_length=32) def __str__(self): return self.title class Category(models.Model): """ 博主個人文章分類表 """ nid = models.AutoField(primary_key=True) title = models.CharField(verbose_name=分類標題, max_length=32) blog = models.ForeignKey(verbose_name=所屬博客, to=Blog, to_field=nid, on_delete=models.CASCADE) def __str__(self): return self.title class Tag(models.Model): nid = models.AutoField(primary_key=True) title = models.CharField(verbose_name=標簽名稱, max_length=32) blog = models.ForeignKey(verbose_name=所屬博客, to=Blog, to_field=nid, on_delete=models.CASCADE) def __str__(self): return self.title class Article(models.Model): nid = models.AutoField(primary_key=True) title = models.CharField(max_length=50, verbose_name=文章標題) desc = models.CharField(max_length=255, verbose_name=文章描述) create_time = models.DateTimeField(verbose_name=創建時間, auto_now_add=True) content = models.TextField() comment_count = models.IntegerField(default=0) up_count = models.IntegerField(default=0) down_count = models.IntegerField(default=0) user = models.ForeignKey(verbose_name=作者, to=UserInfo, to_field=nid, on_delete=models.CASCADE) category = models.ForeignKey(to=Category, to_field=nid, null=True, on_delete=models.CASCADE) tags = models.ManyToManyField( to="Tag", through=Article2Tag, through_fields=(article, tag), ) def __str__(self): return self.title class Article2Tag(models.Model): nid = models.AutoField(primary_key=True) article = models.ForeignKey(verbose_name=文章, to="Article", to_field=nid, on_delete=models.CASCADE) tag = models.ForeignKey(verbose_name=標簽, to="Tag", to_field=nid, on_delete=models.CASCADE) class Meta: unique_together = [ (article, tag), ] def __str__(self): v = self.article.title + "---" + self.tag.title return v class ArticleUpDown(models.Model): """ 點贊表 """ nid = models.AutoField(primary_key=True) user = models.ForeignKey(UserInfo, null=True, on_delete=models.CASCADE) article = models.ForeignKey("Article", null=True, on_delete=models.CASCADE) is_up = models.BooleanField(default=True) class Meta: unique_together = [ (article, user), ] class Comment(models.Model): """ 評論表 """ nid = models.AutoField(primary_key=True) article = models.ForeignKey(verbose_name=評論文章, to=Article, to_field=nid, on_delete=models.CASCADE) user = models.ForeignKey(verbose_name=評論者, to=UserInfo, to_field=nid, on_delete=models.CASCADE) content = models.CharField(verbose_name=評論內容, max_length=255) create_time = models.DateTimeField(verbose_name=創建時間, auto_now_add=True) parent_comment = models.ForeignKey(self, null=True, on_delete=models.CASCADE) def __str__(self): return self.content
View Code

  1. 用戶信息表
  2. 博客信息表
  3. 博主個人文章分類表
  4. 博主個人文章標簽表
  5. 博文表
  6. 文章標簽關聯表
  7. 點贊表
  8. 評論表

3. 功能開發

4. 功能測試

5. 項目部署上線

Django——博客項目