一个文档管理系统,本来数据库用的是mysql,但是现在需要改为mongodb数据库,对mongodb不熟悉,求求大佬们指导一下小弟都需要改写什么,我只在settings.py里面连接了数据库,具体在models.py里怎么改写。
settings.py
DATABASES = { 'default': { 'ENGINE': None, # 'ENGINE': 'django.db.backends.mysql', # 'NAME': 'test1', # 'USER': 'root', # 'PASSWORD': 'root', # 'HOST': '127.0.0.1', } } from mongoengine import connect connect('test')
models.py(files)
from datetime import datetime from mongoengine import * from django.db import models # 文件model class File(models.Model): fileno = models.CharField(max_length=18, verbose_name='文件编号') filename = models.CharField(max_length=200, verbose_name='文件名称') filepath = models.CharField(max_length=200, verbose_name='文件路径') owner = models.CharField(max_length=30, verbose_name='文件所属用户') add_time = models.DateTimeField(default=datetime.now, verbose_name='上传时间') first_check = models.CharField(max_length=1, choices=(('0', '未审批'), ('1', '已审批')), verbose_name='初审', default='0') second_check = models.CharField(max_length=1, choices=(('0', '未审批'), ('1', '已审批')), verbose_name='二审', default='0') isapprove = models.CharField(max_length=1, choices=(('0', '未审批'), ('1', '已审批'), ('2', '已驳回')), verbose_name='终审', default='0') class Meta: verbose_name = '文件' verbose_name_plural = verbose_name def __str__(self): return self.filename # 文件审批日志model class ApproveLog(models.Model): fileno = models.CharField(max_length=18, verbose_name='文件编号') filename = models.CharField(max_length=200, verbose_name='文件名称') owner = models.CharField(max_length=30, verbose_name='文件所属用户') add_time = models.DateTimeField(verbose_name='上传时间') isapprove = models.CharField(max_length=1, choices=(('1', '已审批'), ('2', '已驳回')), verbose_name='终审') approve_time = models.DateTimeField(default=datetime.now, verbose_name='审批时间') class Meta: verbose_name = '文件审批日志' verbose_name_plural = verbose_name def __str__(self): return self.filename # 公用电脑ip地址model class PublicIp(models.Model): host_ip = models.CharField(max_length=300, verbose_name='公用电脑ip地址', blank=True) class Meta: verbose_name = '公用电脑ip地址' verbose_name_plural = verbose_name def __str__(self): return self.host_ip
models.py(users)
from datetime import datetime from django.db import models from django.contrib.auth.models import AbstractUser # 定义用户模型,添加额外的字段 class UserProfile(AbstractUser): userno = models.CharField(max_length=15, verbose_name='工号') department = models.CharField(max_length=15, verbose_name='部门', blank=True) role = models.CharField(max_length=1, choices=(('3', '监察稽核员'), ('2', '系统管理员'), ('1', '普通员工'), ('0', '离职员工')), verbose_name='用户角色', default='1') sub_role = models.CharField(max_length=1, choices=(('2', '二审员'), ('1', '初审员'), ('0', '')), verbose_name='子角色', default='0') is_superuser = models.IntegerField(verbose_name='超级管理员', default=0) add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间') class Meta: verbose_name = '用户信息' verbose_name_plural = verbose_name def __str__(self): return self.username # 定义用户操作日志模型 class UserOperateLog(models.Model): userno = models.CharField(max_length=15, verbose_name='工号') username = models.CharField(max_length=20, verbose_name='姓名') type = models.CharField(max_length=20, verbose_name='操作类型') comment = models.CharField(max_length=20, verbose_name='备注') fileno = models.CharField(max_length=18, verbose_name='文件编号') filename = models.CharField(max_length=200, verbose_name='文件名称') modify_time = models.DateTimeField(default=datetime.now, verbose_name='操作时间') class Meta: verbose_name = '用户操作日志' verbose_name_plural = verbose_name def __str__(self): return self.username + '.' + self.type