discuz贴的代码没有高亮,排版也不太好看,感兴趣的可以前往我的博客看一下:
首先展示一下Django的表结构: class Category(models.Model): category_name = models.CharField(max_length=200) def __str__(self): if self.category_name: return self.category_name class Meta: verbose_name = “分类” verbose_name_plural = verbose_name class Tag(models.Model): tag_name = models.TextField(max_length=100) def __str__(self): if self.tag_name: return self.tag_name class Meta: verbose_name = “标签” verbose_name_plural = verbose_name class PostManager(models.Manager): def distinct_date(self): # 该管理器定义了一个distinct_date方法,目的是找出所有的不同日期 distinct_date_list = [] # 建立一个列表用来存放不同的日期 年-月 date_list = self.values(‘post_date’) # 根据文章字段date_publish找出所有文章的发布时间 for date in date_list: # 对所有日期进行遍历,当然这里会有许多日期是重复的,目的就是找出多少种日期 date = date[‘post_date’].strftime(‘%Y年%m月’) # 取出一个日期改格式为 ‘xxx年/xxx月 存档’ if date not in distinct_date_list: distinct_date_list.append(date) return distinct_date_list class Post(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(max_length=255,unique=True) author = models.ForeignKey(User, on_delete=models.CASCADE) post_date = models.DateTimeField(auto_now_add=True) comment_status = models.CharField(choices=COMMENT_STATUS_CHOICES, default=(‘opened’, ‘opened’), max_length=20) content = RichTextUploadingField(config_name=’default’) tag = models.ManyToManyField(‘Tag’, blank=True) category = models.ForeignKey(Category, related_name=’category’, null=True, on_delete=models.CASCADE) objects = PostManager() is_wordpress = models.CharField(choices=IS_WORDPRESS, default=(‘yes’, ‘yes’), max_length=10) price = models.FloatField(blank=True, null=True) class Meta: verbose_name = “文章” verbose_name_plural = ‘\u200B’ + verbose_name ordering = [“-post_date”] def __str__(self): if self.title: return self.title def get_absolute_url(self): return reverse(‘article_detail’, args=[str(self.slug)]) class Comments(MPTTModel): post = models.ForeignKey(Post, on_delete=models.CASCADE) user_name = models.CharField(max_length=20) email = models.CharField(max_length=50) comment_date = models.DateTimeField(auto_now=True) content = models.TextField(max_length=1000) parent = TreeForeignKey(‘self’, on_delete=models.CASCADE, null=True, blank=True, related_name=’children’) approved = models.CharField(choices=COMMENT_APPROVED_CHOICES, default=(‘refused’, ‘refused’), max_length=20) def __str__(self): if self.content: return self.content class Meta: verbose_name = “评论” verbose_name_plural = verbose_name ordering = [“-comment_date”] class Order(models.Model): order_id = models.CharField(max_length=25) order_done_datetime = models.DateTimeField(auto_now_add=True) slug = models.CharField(max_length=200) def __str__(self): if self.order_id: return self.order_id class Meta: verbose_name = “订单” verbose_name_plural = verbose_name ordering = [“-order_done_datetime”]复制代码
然后是WordPress迁移到Django的实战代码:
[code]#!/usr/bin/env python3
# coding=utf-8
import pymysql
import sqlite3
from pymysql.connections import Connection
from pymysql.cursors import Cursor
from pymysql.connections import Connection as MyConnection
class MysqlConn():
def db_connector(self) -> Connection:
“””
功能:用于数据库初始化连接,获取db实例对象
:return: db连接对象
“””
common_db_config = {‘host’: ‘192.168.0.1’,
‘user’: ‘root’,
‘port’: 3306,
‘passwd’: ‘123456root’,
黑龙江省网友说:卧槽,第一次发表被拦截了,第二次怎么被截断了,感兴趣的去我博客看一下吧
浙江省网友说:大佬们 现在做站用什么程序 ?
江苏省网友说:广告屏蔽进不去
贵州省网友说:现在用的wp哈
河南省网友说:支持技术贴
海南省网友说:支持技术贴
河南省网友说:帮忙加一下白名单再试试哈~