1、在models.py中加入流程接口表和单一接口表
代码如下:
from django.db import models
from product.models import Product
# Create your models here.
class Apitest(models.Model):
apitestname = models.CharField('流程接口名称', max_length=64)
apitester = models.CharField('测试负责人', max_length=16)
apitestresult = models.BooleanField('测试结果')
create_time = models.DateTimeField('创建时间', auto_now=True)
class Meta:
verbose_name = '流程场景接口'
verbose_name_plural = '流程场景接口'
def __str__(self):
return self.apitestname
class Apistep(models.Model):
Apitest = models.ForeignKey('Apitest', on_delete=models.CASCADE,)
apistep = models.CharField('测试步骤', max_length=100, null=True)
apiname = models.CharField('接口地址', max_length=100)
apiurl = models.CharField('url地址', max_length=200)
apiparamvalue = models.CharField('请求参数和值', max_length=800)
apimethod = models.CharField(verbose_name='请求方法', default='get', max_length=200,
null=True)
apiresult = models.CharField('预测结果', max_length=200)
apistatus = models.BooleanField('是否通过')
creat_time = models.DateTimeField('创建时间', auto_now_add=True)
def __str__(self):
return self.apiname
在admin.py中加入以下代码保证功能实现:
from django.contrib import admin
from apitest.models import Apitest, Apistep
class ApistepAdmin(admin.TabularInline):
list_display = ['apiname', 'apiurl', 'apiparamvalue', 'apimethod', 'apiresult', 'apistatus', 'create_time', 'id',
'apitest']
model = Apistep
extra = 1
class ApitestAdmin(admin.ModelAdmin):
list_display = ['apitestname', 'apitester', 'apitestresult', 'create_time', 'id']
inlines = [ApistepAdmin]
admin.site.register(Apitest, ApitestAdmin)
2、同步数据库跟前面的命令行操作一致
3、查看结果
有这个功能出现则说明成功
4、查看数据库是否成功建立
如图:
有这两个表出现即可