python(django)之流程接口管理后台开发

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、查看数据库是否成功建立

如图:

有这两个表出现即可

相关推荐
喝凉白开都长肉的大胖子33 分钟前
在 Matplotlib 中fontweight一般怎么设置
python·matplotlib
HAPPY酷2 小时前
Python高级架构师之路——从原理到实战
java·python·算法
Thomas.Sir2 小时前
第十三章:RAG知识库开发之【GraphRAG 从基础到实战】
python·ai·rag·graphrag
一个处女座的程序猿O(∩_∩)O3 小时前
Python基础知识大全:从零开始掌握Python核心语法
开发语言·python
小陈工3 小时前
Python Web开发入门(十一):RESTful API设计原则与最佳实践——让你的API既优雅又好用
开发语言·前端·人工智能·后端·python·安全·restful
deephub3 小时前
ADK 多智能体编排:SequentialAgent、ParallelAgent 与 LoopAgent 解析
人工智能·python·大语言模型·agent
FL16238631293 小时前
基于yolov26+pyqt5的混凝土墙面缺陷检测系统python源码+pytorch模型+评估指标曲线+精美GUI界面
python·qt·yolo
cxr8284 小时前
GPU 加速声场求解器 CUDA Kernel 实现细节 —— 高频超声传播仿真并行计算引擎
人工智能·python·目标跟踪
枫叶林FYL4 小时前
第10章 符号推理与神经符号AI
pytorch·python·深度学习
nimadan125 小时前
剧本杀app2025推荐,多类型剧本体验与社交互动优势
人工智能·python