from django.db import models


# Create your models here.

# 单质库
class Simplelib(models.Model):

    type = models.IntegerField()  # 区别单质还是混合 0表示单质 1混合
    zhname = models.CharField(max_length=256)  # 名称
    enname = models.CharField(max_length=256, null=True)  # 英文名称
    linkable = models.IntegerField()  # 表示是否可以连接  0表示不可以连接 ， 1表示可以连接
    nickname = models.CharField(max_length=256, null=True)  # 别名(俗名)
    cas = models.CharField(max_length=256, null=True)  # CAS号
    formula = models.CharField(max_length=256, null=True)  # 分子式
    formulaWeight = models.CharField(max_length=256, null=True)  # 相对分子质量
    OxygenBalance = models.CharField(max_length=256, null=True)  # 氧平衡
    nitrogen = models.CharField(max_length=256, null=True)  # 含氮量
    relativeDensity = models.CharField(max_length=256, null=True)  # 相对密度
    meltingPoint = models.CharField(max_length=256, null=True)  # 熔点
    boilingPoint = models.CharField(max_length=256, null=True)  # 沸点
    flashPoint = models.CharField(max_length=256, null=True)  # 闪点
    decompTemp = models.CharField(max_length=256, null=True)  # 分解温度
    standardHeat = models.CharField(max_length=256, null=True)  # 标准生成热
    heatCapacity = models.CharField(max_length=256, null=True)  # 热容
    note = models.TextField(null=True)  # 安全处置方法
    character = models.TextField(null=True)  # 性状
    standardmg = models.CharField(max_length=256, null=True)  # 标准摩尔生成焓
    wettability = models.CharField(max_length=256, null=True)  # 易湿性
    combustionheat = models.CharField(max_length=256, null=True)  # 燃烧热
    burstspeed = models.CharField(max_length=256, null=True)  # 爆速
    temp = models.CharField(max_length=256, null=True)  # 爆温
    bursthot = models.CharField(max_length=256, null=True)  # 爆热
    burstpress = models.CharField(max_length=256, null=True)  # 爆压
    burstvol = models.CharField(max_length=256, null=True)  # 爆容
    burstpoint = models.CharField(max_length=256, null=True)  # 5S爆发点
    frisen = models.TextField(null=True)  # 摩擦感度
    impsen = models.TextField(null=True)  # 撞击感度
    stasen = models.TextField(null=True)  # 静电感度
    explosionlimit = models.TextField(null=True)  # 爆炸极限
    svp = models.CharField(max_length=256, null=True)  # 蒸气压
    img = models.CharField(max_length=256, null=True)  # imgtable表中数据的id列表
    visible = models.IntegerField()  # 删除 0不可见 1可见
    audit = models.IntegerField(default=0)  # 表示是否审核中   0表示审核中 1表示审核未通过 2审核通过
    version = models.IntegerField()  # 版本 版本号表中找最大加1

    class Meta:
        managed = True
        db_table = 'simplelib'


# 爆炸案
class Bombinfo(models.Model):

    casename = models.CharField(max_length=256)  # 按键名称 添加编辑带上
    time = models.IntegerField()  # 时间
    addr = models.CharField(max_length=256)  # 发生地
    casualties = models.CharField(max_length=256)  # 伤亡情况
    visible = models.IntegerField()  # 删除 0不可见 1可见
    audit = models.IntegerField(default=0)  # 表示是否审核中   0表示审核中 1表示审核未通过 2审核通过
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = "bombinfo"


# 类别表
class CategoryTable(models.Model):

    pid = models.IntegerField()  # 父节点id
    tb = models.CharField(max_length=256, null=True)  # 表名
    tbid = models.IntegerField(null=True)  # 表id
    name = models.CharField(max_length=256, null=True)  # 节点名称
    visible = models.IntegerField()  # 表示是否删除，0不可见 1可见
    type = models.IntegerField()  # 库类型 0单质库 1混合库  2备用
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = 'categorytable'


# 关系表
class RelationTable(models.Model):

    audit = models.IntegerField(default=0)  # 审核状态 0表示审核中 1表示审核未通过 2审核通过
    stb = models.CharField(max_length=256, null=True)  # 连接原数据表名
    sid = models.IntegerField(null=True)  # 连接原数据id
    content = models.TextField(null=True)  # 链接内容
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = 'relationtable'


# 审核列表
class CheckTable(models.Model):

    stb = models.CharField(max_length=256, null=True)  # 连接原数据表名
    sid = models.IntegerField(null=True)  # 连接原数据id
    tid = models.IntegerField(null=True)  # 修改目标id
    audit = models.IntegerField(default=0)  # 审核状态 0表示审核中 1表示审核未通过 2审核通过
    method = models.IntegerField()  # 操作方式，0是添加，1是修改，2是删除
    account = models.CharField(max_length=20, null=True)  # 账号
    content = models.TextField(null=True)  # 内容
    time = models.IntegerField(null=True)  # 时间
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = 'checktable'



class ImgTable(models.Model):

    md5 = models.CharField(max_length=256, null=True)  # 对文件内容的md5值计算
    paths = models.CharField(max_length=256, null=True)  # 图片的路径
    version = models.IntegerField()  # 数据版本号

    class Meta:
        managed = True
        db_table = 'imgtable'


class User(models.Model):

    type = models.IntegerField()  # 用户类型 0管理员， 1普通用户
    name = models.CharField(max_length=256)  # 用户名
    account = models.CharField(max_length=256)  # 账户
    pwd = models.CharField(max_length=256)  # 密码
    phone = models.CharField(max_length=256)  # 电话
    visible = models.IntegerField()  # 表示是否删除，0不可见 1可见
    audit = models.IntegerField()   # 审核状态 0表示审核中 1表示审核未通过 2审核通过
    version = models.IntegerField()  # 数据版本号

    class Meta:
        managed = True
        db_table = "usertable"


# 版本号表
class VersionTable(models.Model):
    tb_name = models.CharField(max_length=256)  # 表名
    max_version = models.IntegerField()  # 最大版本号

    class Meta:
        managed = True
        db_table = "versiontable"




MP_TABLE = dict(
    simplelib=Simplelib,
    bombinfo=Bombinfo,
    tablecategory=CategoryTable,
    relationtable=RelationTable,
    checklist=CheckTable,
    imgtable=ImgTable,
    usertable=User,
)

import json
from django.core import serializers


def HelpGet(data, tb=None):
    def f(d):
        v = dict(id=d['pk'], data_size=0, ** d['fields'])
        if tb:
            v['data_size'] = tb[d['fields']['tb_name']].objects.count()
        # print(v)
        return v

    return [f(d) for d in json.loads(serializers.serialize('json', data))]

    # rt=[]
    # for d in json.loads(serializers.serialize('json', data)):
    #     rt.append(dict(pk=d['pk'],**d['fields']))
    # return rt

8b174e0a5b572b312152502b43959f2b9622eb2f
<mask token>


class Bombinfo(models.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>


    class Meta:
        managed = True
        db_table = 'bombinfo'


class CategoryTable(models.Model):
    pid = models.IntegerField()
    tb = models.CharField(max_length=256, null=True)
    tbid = models.IntegerField(null=True)
    name = models.CharField(max_length=256, null=True)
    visible = models.IntegerField()
    type = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'categorytable'


class RelationTable(models.Model):
    audit = models.IntegerField(default=0)
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    content = models.TextField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'relationtable'


class CheckTable(models.Model):
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    tid = models.IntegerField(null=True)
    audit = models.IntegerField(default=0)
    method = models.IntegerField()
    account = models.CharField(max_length=20, null=True)
    content = models.TextField(null=True)
    time = models.IntegerField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'checktable'


class ImgTable(models.Model):
    md5 = models.CharField(max_length=256, null=True)
    paths = models.CharField(max_length=256, null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'imgtable'


class User(models.Model):
    type = models.IntegerField()
    name = models.CharField(max_length=256)
    account = models.CharField(max_length=256)
    pwd = models.CharField(max_length=256)
    phone = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'usertable'


class VersionTable(models.Model):
    tb_name = models.CharField(max_length=256)
    max_version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'versiontable'


<mask token>

<mask token>


class Simplelib(models.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>


    class Meta:
        managed = True
        db_table = 'simplelib'


class Bombinfo(models.Model):
    casename = models.CharField(max_length=256)
    time = models.IntegerField()
    addr = models.CharField(max_length=256)
    casualties = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField(default=0)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'bombinfo'


class CategoryTable(models.Model):
    pid = models.IntegerField()
    tb = models.CharField(max_length=256, null=True)
    tbid = models.IntegerField(null=True)
    name = models.CharField(max_length=256, null=True)
    visible = models.IntegerField()
    type = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'categorytable'


class RelationTable(models.Model):
    audit = models.IntegerField(default=0)
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    content = models.TextField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'relationtable'


class CheckTable(models.Model):
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    tid = models.IntegerField(null=True)
    audit = models.IntegerField(default=0)
    method = models.IntegerField()
    account = models.CharField(max_length=20, null=True)
    content = models.TextField(null=True)
    time = models.IntegerField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'checktable'


class ImgTable(models.Model):
    md5 = models.CharField(max_length=256, null=True)
    paths = models.CharField(max_length=256, null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'imgtable'


class User(models.Model):
    type = models.IntegerField()
    name = models.CharField(max_length=256)
    account = models.CharField(max_length=256)
    pwd = models.CharField(max_length=256)
    phone = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'usertable'


class VersionTable(models.Model):
    tb_name = models.CharField(max_length=256)
    max_version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'versiontable'


<mask token>

<mask token>


class Simplelib(models.Model):
    type = models.IntegerField()
    zhname = models.CharField(max_length=256)
    enname = models.CharField(max_length=256, null=True)
    linkable = models.IntegerField()
    nickname = models.CharField(max_length=256, null=True)
    cas = models.CharField(max_length=256, null=True)
    formula = models.CharField(max_length=256, null=True)
    formulaWeight = models.CharField(max_length=256, null=True)
    OxygenBalance = models.CharField(max_length=256, null=True)
    nitrogen = models.CharField(max_length=256, null=True)
    relativeDensity = models.CharField(max_length=256, null=True)
    meltingPoint = models.CharField(max_length=256, null=True)
    boilingPoint = models.CharField(max_length=256, null=True)
    flashPoint = models.CharField(max_length=256, null=True)
    decompTemp = models.CharField(max_length=256, null=True)
    standardHeat = models.CharField(max_length=256, null=True)
    heatCapacity = models.CharField(max_length=256, null=True)
    note = models.TextField(null=True)
    character = models.TextField(null=True)
    standardmg = models.CharField(max_length=256, null=True)
    wettability = models.CharField(max_length=256, null=True)
    combustionheat = models.CharField(max_length=256, null=True)
    burstspeed = models.CharField(max_length=256, null=True)
    temp = models.CharField(max_length=256, null=True)
    bursthot = models.CharField(max_length=256, null=True)
    burstpress = models.CharField(max_length=256, null=True)
    burstvol = models.CharField(max_length=256, null=True)
    burstpoint = models.CharField(max_length=256, null=True)
    frisen = models.TextField(null=True)
    impsen = models.TextField(null=True)
    stasen = models.TextField(null=True)
    explosionlimit = models.TextField(null=True)
    svp = models.CharField(max_length=256, null=True)
    img = models.CharField(max_length=256, null=True)
    visible = models.IntegerField()
    audit = models.IntegerField(default=0)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'simplelib'


class Bombinfo(models.Model):
    casename = models.CharField(max_length=256)
    time = models.IntegerField()
    addr = models.CharField(max_length=256)
    casualties = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField(default=0)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'bombinfo'


class CategoryTable(models.Model):
    pid = models.IntegerField()
    tb = models.CharField(max_length=256, null=True)
    tbid = models.IntegerField(null=True)
    name = models.CharField(max_length=256, null=True)
    visible = models.IntegerField()
    type = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'categorytable'


class RelationTable(models.Model):
    audit = models.IntegerField(default=0)
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    content = models.TextField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'relationtable'


class CheckTable(models.Model):
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    tid = models.IntegerField(null=True)
    audit = models.IntegerField(default=0)
    method = models.IntegerField()
    account = models.CharField(max_length=20, null=True)
    content = models.TextField(null=True)
    time = models.IntegerField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'checktable'


class ImgTable(models.Model):
    md5 = models.CharField(max_length=256, null=True)
    paths = models.CharField(max_length=256, null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'imgtable'


class User(models.Model):
    type = models.IntegerField()
    name = models.CharField(max_length=256)
    account = models.CharField(max_length=256)
    pwd = models.CharField(max_length=256)
    phone = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'usertable'


class VersionTable(models.Model):
    tb_name = models.CharField(max_length=256)
    max_version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'versiontable'


<mask token>

from django.db import models


class Simplelib(models.Model):
    type = models.IntegerField()
    zhname = models.CharField(max_length=256)
    enname = models.CharField(max_length=256, null=True)
    linkable = models.IntegerField()
    nickname = models.CharField(max_length=256, null=True)
    cas = models.CharField(max_length=256, null=True)
    formula = models.CharField(max_length=256, null=True)
    formulaWeight = models.CharField(max_length=256, null=True)
    OxygenBalance = models.CharField(max_length=256, null=True)
    nitrogen = models.CharField(max_length=256, null=True)
    relativeDensity = models.CharField(max_length=256, null=True)
    meltingPoint = models.CharField(max_length=256, null=True)
    boilingPoint = models.CharField(max_length=256, null=True)
    flashPoint = models.CharField(max_length=256, null=True)
    decompTemp = models.CharField(max_length=256, null=True)
    standardHeat = models.CharField(max_length=256, null=True)
    heatCapacity = models.CharField(max_length=256, null=True)
    note = models.TextField(null=True)
    character = models.TextField(null=True)
    standardmg = models.CharField(max_length=256, null=True)
    wettability = models.CharField(max_length=256, null=True)
    combustionheat = models.CharField(max_length=256, null=True)
    burstspeed = models.CharField(max_length=256, null=True)
    temp = models.CharField(max_length=256, null=True)
    bursthot = models.CharField(max_length=256, null=True)
    burstpress = models.CharField(max_length=256, null=True)
    burstvol = models.CharField(max_length=256, null=True)
    burstpoint = models.CharField(max_length=256, null=True)
    frisen = models.TextField(null=True)
    impsen = models.TextField(null=True)
    stasen = models.TextField(null=True)
    explosionlimit = models.TextField(null=True)
    svp = models.CharField(max_length=256, null=True)
    img = models.CharField(max_length=256, null=True)
    visible = models.IntegerField()
    audit = models.IntegerField(default=0)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'simplelib'


class Bombinfo(models.Model):
    casename = models.CharField(max_length=256)
    time = models.IntegerField()
    addr = models.CharField(max_length=256)
    casualties = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField(default=0)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'bombinfo'


class CategoryTable(models.Model):
    pid = models.IntegerField()
    tb = models.CharField(max_length=256, null=True)
    tbid = models.IntegerField(null=True)
    name = models.CharField(max_length=256, null=True)
    visible = models.IntegerField()
    type = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'categorytable'


class RelationTable(models.Model):
    audit = models.IntegerField(default=0)
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    content = models.TextField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'relationtable'


class CheckTable(models.Model):
    stb = models.CharField(max_length=256, null=True)
    sid = models.IntegerField(null=True)
    tid = models.IntegerField(null=True)
    audit = models.IntegerField(default=0)
    method = models.IntegerField()
    account = models.CharField(max_length=20, null=True)
    content = models.TextField(null=True)
    time = models.IntegerField(null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'checktable'


class ImgTable(models.Model):
    md5 = models.CharField(max_length=256, null=True)
    paths = models.CharField(max_length=256, null=True)
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'imgtable'


class User(models.Model):
    type = models.IntegerField()
    name = models.CharField(max_length=256)
    account = models.CharField(max_length=256)
    pwd = models.CharField(max_length=256)
    phone = models.CharField(max_length=256)
    visible = models.IntegerField()
    audit = models.IntegerField()
    version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'usertable'


class VersionTable(models.Model):
    tb_name = models.CharField(max_length=256)
    max_version = models.IntegerField()


    class Meta:
        managed = True
        db_table = 'versiontable'


MP_TABLE = dict(simplelib=Simplelib, bombinfo=Bombinfo, tablecategory=
    CategoryTable, relationtable=RelationTable, checklist=CheckTable,
    imgtable=ImgTable, usertable=User)
import json
from django.core import serializers


def HelpGet(data, tb=None):

    def f(d):
        v = dict(id=d['pk'], data_size=0, **d['fields'])
        if tb:
            v['data_size'] = tb[d['fields']['tb_name']].objects.count()
        return v
    return [f(d) for d in json.loads(serializers.serialize('json', data))]

from django.db import models


# Create your models here.

# 单质库
class Simplelib(models.Model):

    type = models.IntegerField()  # 区别单质还是混合 0表示单质 1混合
    zhname = models.CharField(max_length=256)  # 名称
    enname = models.CharField(max_length=256, null=True)  # 英文名称
    linkable = models.IntegerField()  # 表示是否可以连接  0表示不可以连接 ， 1表示可以连接
    nickname = models.CharField(max_length=256, null=True)  # 别名(俗名)
    cas = models.CharField(max_length=256, null=True)  # CAS号
    formula = models.CharField(max_length=256, null=True)  # 分子式
    formulaWeight = models.CharField(max_length=256, null=True)  # 相对分子质量
    OxygenBalance = models.CharField(max_length=256, null=True)  # 氧平衡
    nitrogen = models.CharField(max_length=256, null=True)  # 含氮量
    relativeDensity = models.CharField(max_length=256, null=True)  # 相对密度
    meltingPoint = models.CharField(max_length=256, null=True)  # 熔点
    boilingPoint = models.CharField(max_length=256, null=True)  # 沸点
    flashPoint = models.CharField(max_length=256, null=True)  # 闪点
    decompTemp = models.CharField(max_length=256, null=True)  # 分解温度
    standardHeat = models.CharField(max_length=256, null=True)  # 标准生成热
    heatCapacity = models.CharField(max_length=256, null=True)  # 热容
    note = models.TextField(null=True)  # 安全处置方法
    character = models.TextField(null=True)  # 性状
    standardmg = models.CharField(max_length=256, null=True)  # 标准摩尔生成焓
    wettability = models.CharField(max_length=256, null=True)  # 易湿性
    combustionheat = models.CharField(max_length=256, null=True)  # 燃烧热
    burstspeed = models.CharField(max_length=256, null=True)  # 爆速
    temp = models.CharField(max_length=256, null=True)  # 爆温
    bursthot = models.CharField(max_length=256, null=True)  # 爆热
    burstpress = models.CharField(max_length=256, null=True)  # 爆压
    burstvol = models.CharField(max_length=256, null=True)  # 爆容
    burstpoint = models.CharField(max_length=256, null=True)  # 5S爆发点
    frisen = models.TextField(null=True)  # 摩擦感度
    impsen = models.TextField(null=True)  # 撞击感度
    stasen = models.TextField(null=True)  # 静电感度
    explosionlimit = models.TextField(null=True)  # 爆炸极限
    svp = models.CharField(max_length=256, null=True)  # 蒸气压
    img = models.CharField(max_length=256, null=True)  # imgtable表中数据的id列表
    visible = models.IntegerField()  # 删除 0不可见 1可见
    audit = models.IntegerField(default=0)  # 表示是否审核中   0表示审核中 1表示审核未通过 2审核通过
    version = models.IntegerField()  # 版本 版本号表中找最大加1

    class Meta:
        managed = True
        db_table = 'simplelib'


# 爆炸案
class Bombinfo(models.Model):

    casename = models.CharField(max_length=256)  # 按键名称 添加编辑带上
    time = models.IntegerField()  # 时间
    addr = models.CharField(max_length=256)  # 发生地
    casualties = models.CharField(max_length=256)  # 伤亡情况
    visible = models.IntegerField()  # 删除 0不可见 1可见
    audit = models.IntegerField(default=0)  # 表示是否审核中   0表示审核中 1表示审核未通过 2审核通过
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = "bombinfo"


# 类别表
class CategoryTable(models.Model):

    pid = models.IntegerField()  # 父节点id
    tb = models.CharField(max_length=256, null=True)  # 表名
    tbid = models.IntegerField(null=True)  # 表id
    name = models.CharField(max_length=256, null=True)  # 节点名称
    visible = models.IntegerField()  # 表示是否删除，0不可见 1可见
    type = models.IntegerField()  # 库类型 0单质库 1混合库  2备用
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = 'categorytable'


# 关系表
class RelationTable(models.Model):

    audit = models.IntegerField(default=0)  # 审核状态 0表示审核中 1表示审核未通过 2审核通过
    stb = models.CharField(max_length=256, null=True)  # 连接原数据表名
    sid = models.IntegerField(null=True)  # 连接原数据id
    content = models.TextField(null=True)  # 链接内容
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = 'relationtable'


# 审核列表
class CheckTable(models.Model):

    stb = models.CharField(max_length=256, null=True)  # 连接原数据表名
    sid = models.IntegerField(null=True)  # 连接原数据id
    tid = models.IntegerField(null=True)  # 修改目标id
    audit = models.IntegerField(default=0)  # 审核状态 0表示审核中 1表示审核未通过 2审核通过
    method = models.IntegerField()  # 操作方式，0是添加，1是修改，2是删除
    account = models.CharField(max_length=20, null=True)  # 账号
    content = models.TextField(null=True)  # 内容
    time = models.IntegerField(null=True)  # 时间
    version = models.IntegerField()  # 版本

    class Meta:
        managed = True
        db_table = 'checktable'



class ImgTable(models.Model):

    md5 = models.CharField(max_length=256, null=True)  # 对文件内容的md5值计算
    paths = models.CharField(max_length=256, null=True)  # 图片的路径
    version = models.IntegerField()  # 数据版本号

    class Meta:
        managed = True
        db_table = 'imgtable'


class User(models.Model):

    type = models.IntegerField()  # 用户类型 0管理员， 1普通用户
    name = models.CharField(max_length=256)  # 用户名
    account = models.CharField(max_length=256)  # 账户
    pwd = models.CharField(max_length=256)  # 密码
    phone = models.CharField(max_length=256)  # 电话
    visible = models.IntegerField()  # 表示是否删除，0不可见 1可见
    audit = models.IntegerField()   # 审核状态 0表示审核中 1表示审核未通过 2审核通过
    version = models.IntegerField()  # 数据版本号

    class Meta:
        managed = True
        db_table = "usertable"


# 版本号表
class VersionTable(models.Model):
    tb_name = models.CharField(max_length=256)  # 表名
    max_version = models.IntegerField()  # 最大版本号

    class Meta:
        managed = True
        db_table = "versiontable"




MP_TABLE = dict(
    simplelib=Simplelib,
    bombinfo=Bombinfo,
    tablecategory=CategoryTable,
    relationtable=RelationTable,
    checklist=CheckTable,
    imgtable=ImgTable,
    usertable=User,
)

import json
from django.core import serializers


def HelpGet(data, tb=None):
    def f(d):
        v = dict(id=d['pk'], data_size=0, ** d['fields'])
        if tb:
            v['data_size'] = tb[d['fields']['tb_name']].objects.count()
        # print(v)
        return v

    return [f(d) for d in json.loads(serializers.serialize('json', data))]

    # rt=[]
    # for d in json.loads(serializers.serialize('json', data)):
    #     rt.append(dict(pk=d['pk'],**d['fields']))
    # return rt
