当前位置:网站首页>DRF generating serialization class code
DRF generating serialization class code
2022-08-01 23:08:00 【Ali's love letter】
一、简介
drfIt is too cumbersome to generate serialization class code,So here the code is automatically generated and then pasted.
二、使用方法
- 导入models中的类
- Copy the run results to
serializer.py文件中.
The places that need to be modified have been commented in the code
import django, os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "netshop.settings") # 将'netshop'Change it to your own project name
django.setup()
''' Import your own model classes '''
from cartapp.models import CartItem
from goodsapp.models import Category, Goods, GoodsDetailName, GoodDetail, Size, Color, Inventory
from orderapp.models import Order, OrderItem
from userapp.models import Aarea, UserInfo, Address
def generate_serializers(class_):
all_fields = getattr(class_, 'fields', [field.name for field in class_._meta.fields])
class_str = str(class_).split(".")[-1].replace("'>", "")
msg = f'''class {
class_str}Serializer(serializers.ModelSerializer): class Meta: model = {
class_str} fields = {
str(all_fields)}'''
return msg
def serializer_run(class_:list)-> None:
for code_text in map(generate_serializers, class_):
print(code_text, "\n")
''' Modify it to your own model class '''
clss_ = [Category, Goods, GoodsDetailName, GoodDetail, Size, Color, Inventory,Order, OrderItem,Aarea, UserInfo, Address]
serializer_run(clss_)
效果图
边栏推荐
- 论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
- D - Linear Probing- 并查集
- 03. GO language variable definition, function
- 【C补充】链表专题 - 单向链表
- excel remove all carriage return from a cell
- excel change cell size
- PAM Palindromic Automata
- SQL29 Calculate the average next day retention rate of users
- excel change cell size
- 数据库表设计规则
猜你喜欢

xss相关知识点以及从 XSS Payload 学习浏览器解码

Wechat Gymnasium Appointment Mini Program Graduation Design Finished Work (4) Opening Report

TCP 可靠吗?为什么?

drf生成序列化类代码

小程序毕设作品之微信体育馆预约小程序毕业设计成品(2)小程序功能

PDF转Word有那么难吗?做一个文件转换器,都解决了

xctf attack and defense world web master advanced area webshell

访问控制台中的选定节点

APP special test: traffic test
SQL29 Calculate the average next day retention rate of users
随机推荐
图论——强连通分量缩点+拓扑排序
解决端口占用
PHP算法之电话号码的字母组合
PostgreSQL 基础--常用命令
Small application project works WeChat stadium booking applet graduation design of the finished product (1) the development profile
CF1705D Mark and Lightbulbs
JS 数组去重(含简单数组去重、对象数组去重)
小程序毕设作品之微信美食菜谱小程序毕业设计成品(7)中期检查报告
编曲软件FL studio20.8中文版功能和作用
excel remove all carriage return from a cell
移动端人脸风格化技术的应用
【C补充】链表专题 - 单向链表
How to add a game character to a UE4 scene
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
Deep learning Course2 first week Practical aspects of Deep Learning exercises
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
excel vertical to horizontal
Chapter 19 Tips and Traps: Common Goofs for Novices
联邦学习在金融领域的发展和应用
13、学习MySQL 分组