wordpress商品信息整理并通过Django管理

it不难
2022-07-21 / 0 评论 / 7 阅读 / 正在检测是否收录...

前言

Django添加新模块resource

from django.db import models

#状态
U   = 0
Y   = 1
N   = 2

STATUS_CHOICE = {
    U: '未处理',
    Y: '可用',
    N: '不可用',
}

# Create your models here.
class Resource(models.Model):
    '''
    任务模型类
    '''
    id = models.AutoField(primary_key=True)
    rid = models.CharField(max_length=16, verbose_name='编号', default='0')
    rtitle = models.CharField(max_length=256, verbose_name='标题')
    rcontent = models.TextField(max_length=2048*8, verbose_name='说明')
    rparent1 = models.CharField(max_length=128, verbose_name='一级分类', default='0')
    rparent2 = models.CharField(max_length=128, verbose_name='二级分类', default='1')
    rurl = models.CharField(max_length=256, verbose_name='下载链接', default='0')
    rpwd = models.CharField(max_length=256, verbose_name='解压密码', default='0')
    status_choices = ((k, v) for k,v in STATUS_CHOICE.items())
    rstatus = models.SmallIntegerField(default='0', choices=status_choices, verbose_name='状态')

    # admin显示订单的id
    def __str__(self):
        return self.rtitle

    class Meta:
        db_table = 'code_resource'
        verbose_name = '源码资源'
        verbose_name_plural = '源码资源'

# 修改项目settings.py,添加模块
INSTALLED_APPS = [ 
  ...
  'resource', 
  ...
  ],

# 更新
python3 manage.py makemigrations
python3 manage.py migrate

show create table code_resource;

待处理资源wordpress数据库操作

CREATE TABLE `code_resource` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `rid` varchar(16) COLLATE utf8_bin NOT NULL,
  `rtitle` varchar(256) COLLATE utf8_bin NOT NULL,
  `rcontent` longtext COLLATE utf8_bin NOT NULL,
  `rparent1` varchar(128) COLLATE utf8_bin NOT NULL,
  `rparent2` varchar(128) COLLATE utf8_bin NOT NULL,
  `rurl` varchar(256) COLLATE utf8_bin NOT NULL,
  `rpwd` varchar(256) COLLATE utf8_bin NOT NULL,
  `rstatus` smallint(6) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=60031 DEFAULT CHARSET=utf8 COLLATE=utf8_bin

# 导出
 mysqldump  -uroot -pxxxx -h 127.0.0.1  yonp code_resource > code_resource.sql
 
# 导入
mysql -uroot -pxxxx  taskmonitor < code_resource.sql

数据展示

FAQ

django 数据库更新抱错后,重新执行

# 确保存在文件
resource/migrations/__init__.py

# 登录数据库,清理resource模块记录
select * from django_migrations;
0

评论 (0)

取消