Django中反向生成models.py的实例讲解

yipeiwu_com6年前Python基础

命令行中进入Django项目目录,执行

python manage.py inspectdb testmodel_test 

其中testmodel_test为数据表,生成的结果

from django.db import models 
 
class TestmodelTest(models.Model): 
 name = models.CharField(max_length=20) 
 c1 = models.CharField(max_length=255, blank=True, null=True) 
 c2 = models.CharField(max_length=255, blank=True, null=True) 
 
 class Meta: 
 managed = False 
 db_table = 'testmodel_test' 

修改class名后就可直接放到models中使用!

以上这篇Django中反向生成models.py的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 串口读写的实现方法

Python 串口读写的实现方法

1.安装pyserial https://pypi.python.org/pypi/pyserial Doc:http://pythonhosted.org/pyserial/ 使用Py...

在python中bool函数的取值方法

bool是Boolean的缩写,只有真(True)和假(False)两种取值 bool函数只有一个参数,并根据这个参数的值返回真或者假。 1.当对数字使用bool函数时,0返回假(Fal...

python 将对象设置为可迭代的两种实现方法

1、实现 __getitem__(self) class Library(object): def __init__(self): self.value=['a','b'...

在python plt图表中文字大小调节的方法

如下所示: plt.title("Feature importances", fontsize=30) plt.xticks(fontsize=30) plt.yticks(fo...

django 通过URL访问上传的文件方法

django 通过URL访问上传的文件方法

Django2.0 通过URL访问上传的文件(pdf、picture等) Django是一个成熟的web框架,基于python实现,有很多的优点,很容易快速上手(详见官网:https:/...