基于djangorestframework的serializer解析基类, 封装了常用功能, 方便快速开发.
Project description
xy_django_serializer
说明
基于djangorestframework的serializer解析基类, 封装了常用功能, 方便快速开发.
源码仓库
安装
# bash
pip install xy_django_serializer
使用
1. 创建解析类
# serializers.py
from rest_framework import viewsets
from xy_django_serializer.serializers import Serializer
from .models import MImage
class SImage(Serializer):
default_value = ""
class Meta:
model = MImage
fields = "__all__"
class VSImage(viewsets.ModelViewSet):
queryset = MImage.objects.all()
serializer_class = SImage
2. 实现解析
1. 在Django项目的manage.py shell中调用
# Python解释器
from Demo.models import MDemo
from Demo.serializers import SDemo
demo_list = MDemo.objects.all()
demo_dict_list = SDemo(demo_list, many=True).data
print(demo_list)
print(demo_dict_list))
2. 在Tornado等其他运行环境中调用
注意: 必须先加载Django工程到运行的项目中
# Demoes.py
from xy_request_handler_api.Api import Api
from Demo.models import MDemo
from Demo.serializers import SDemo
class DemoApi(Api):
def check_xsrf_cookie(self) -> None:
return None
def check_origin(self, _):
return False
def fetch(self):
all_demo_list = MDemo.objects.all()
all_demo_dict_list = SDemo(all_demo_list, many=True).data
self.success()
self.data = {"all_demo_list": all_demo_dict_list}
self.xy_response()
def get(self):
self.fetch()
def post(self):
self.fetch()
运行 样例工程
样例工程具体使用方式请移步 xy_web_server.git 下列仓库
许可证
xy_django_serializer 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。
捐赠
如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?
联系方式
微信: yuyangiit
邮箱: yuyangit.0515@qq.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xy_django_serializer-1.0.0.tar.gz
.
File metadata
- Download URL: xy_django_serializer-1.0.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560040361097c7c2e556d30f9d615b820c9bcb3a27da826700d50676bb2f676b |
|
MD5 | ff6f02fea86bdea9905f09148334b577 |
|
BLAKE2b-256 | 6113035b40b73c836b39daf9e661d9f563dc90a1a11f3f37a280dabd61b48a88 |
File details
Details for the file xy_django_serializer-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: xy_django_serializer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8006d2640a7290610552b9c0155aae2fb59efe0705cc73059a6fd40f8a82260 |
|
MD5 | 8570b1151eb4a3ebcdadf4b454c99c91 |
|
BLAKE2b-256 | 552d70c77bb74ec88c918cb140a3df6c69ffdf407e3d150c4c06a02be529910b |