Skip to content

Commit

Permalink
专家分类表的建立与相关数据导入脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
MissYourSmile committed Dec 16, 2019
1 parent b063126 commit bbfcb2f
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.vscode
Empty file added Specialist/__init__.py
Empty file.
Binary file added Specialist/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added Specialist/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added Specialist/__pycache__/models.cpython-36.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions Specialist/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from Specialist.models import SpecialistCategory

# Register your models here.
admin.site.register(SpecialistCategory)
5 changes: 5 additions & 0 deletions Specialist/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class SpecialistConfig(AppConfig):
name = 'Specialist'
21 changes: 21 additions & 0 deletions Specialist/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.0 on 2019-12-16 03:10

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='SpecialistCategory',
fields=[
('key', models.CharField(max_length=8, primary_key=True, serialize=False)),
('name', models.CharField(max_length=20)),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions Specialist/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""专家信息模型"""
from django.db import models

# Create your models here.
class SpecialistCategory(models.Model):
"""专家分类
- 分类key key char 8
- 分类名 name char 20
"""
key = models.CharField(max_length=8, primary_key=True)
name = models.CharField(max_length=20)
3 changes: 3 additions & 0 deletions Specialist/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions Specialist/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
3 changes: 1 addition & 2 deletions basic_scirpt/admin_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
"""管理员注册脚本"""
import sys
import os
import django

import re
import hashlib
import getpass

import django
sys.path.append('../')
os.environ['DJANGO_SETTINGS_MODULE'] = 'specialist_info.settings'
django.setup()
Expand Down
38 changes: 38 additions & 0 deletions basic_scirpt/specialist_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""自动化生成数据库中的专家分类表"""
#!/usr/bin/env python3
import re
import docx

import sys
import os
import django
sys.path.append('../')
os.environ['DJANGO_SETTINGS_MODULE'] = 'specialist_info.settings'
django.setup()

from Specialist.models import SpecialistCategory

def save(text):
"""将传入的字符串格式化后存入数据库
分类ID: 如 A01 A0101
分类名称:
"""
ret = re.match(r'^\w{1}\d{2,6}', text)
if ret:
key = ret.group()
val = re.split(r'^\w{1}\d{2,6} *', text)[1]
val = val.replace('\n', '').replace('\r', '')
obj = SpecialistCategory(key=key, name=val)
obj.save()

def main():
"""main"""
doc = docx.Document('type_info.docx')
for table in doc.tables:
for cell in table.columns[0].cells:
save(cell.text)
for cell in table.columns[1].cells:
save(cell.text)

if __name__ == "__main__":
main()
Binary file added basic_scirpt/type_info.docx
Binary file not shown.
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified specialist_info/__pycache__/settings.cpython-36.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions specialist_info/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'UserInfo',
'Specialist',
]

MIDDLEWARE = [
Expand Down

0 comments on commit bbfcb2f

Please sign in to comment.