管理平台接口文档,优化业务流程的灵魂之匙
352
2022-09-05
idc机柜 serial(idc机柜租赁)
from django.conf.urls import urlfrom django.contrib import adminfrom django.urls import path,includefrom rest_framework.routers import DefaultRouterfrom rest_framework.documentation import include_docs_urlsfrom idcs.views import IdcsViewSetroute = DefaultRouter()route.register("idcs",IdcsViewSet,basename="idcs")urlpatterns = [ url(r'^', include(route.urls)), url(r'^docs/', include_docs_urls("运维平台接口文档")),]
from django.shortcuts import render# Create your views here.from rest_framework.viewsets import ModelViewSetfrom idcs.serializers import IdcSerializersfrom .models import idcsclass IdcsViewSet(ModelViewSet): """ list:获取数据 destroy:删除数据 """ queryset = idcs.objects.all() serializer_class = IdcSerializers
from rest_framework import serializersfrom .models import *class IdcSerializers(serializers.Serializer): """ IDC序列化类 """ id = serializers.IntegerField(read_only=True) name = serializers.CharField(required=True,max_length=30,label="IDC名称",help_text="IDC名称") address = serializers.CharField(required=True,max_length=30,label="IDC地址",help_text="IDC地址") phone = serializers.CharField(required=True,max_length=30,label="IDC电话",help_text="IDC电话") email = serializers.EmailField(required=True,label="IDC联系人邮箱",help_text="IDC联系人邮箱") letter = serializers.CharField(required=True,max_length=30,label="idc简称",help_text="idc简称") def create(self, validated_data): return idcs.objects.create(**validated_data) def update(self,instance,validated_data): instance.name = validated_data.get("name",instance.name) instance.address = validated_data.get("address", instance.address) instance.phone = validated_data.get("phone", instance.phone) instance.email = validated_data.get("email", instance.email) instance.letter = validated_data.get("letter", instance.letter) instance.save() return instance# class IdcsSerializer(serializers.ModelSerializer):# """图书数据序列化器"""# class Meta:# model = idcs# fields = '__all__'
from django.db import models# Create your models here.class idcs(models.Model): name = models.CharField(max_length=30,verbose_name="姓名") address = models.CharField(max_length=30,verbose_name="姓名") phone = models.CharField(max_length=30,verbose_name="姓名") email = models.EmailField(verbose_name="邮件") letter = models.CharField(max_length=30,verbose_name="IDC简称") def __str__(self): return self.name class Meta: db_table="idcs"
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~