123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- from rest_framework import serializers
- from django.db.models import Max
- from .models import Bar,Navigation,Company,Slideshow,EditorContens,Hmwe,Hmart,\
- Hmcase,Hmgroup,Hmaddress,Column,WnComponentModel,WnComponentCssModel,WnComponentKeyModel,WnComponentCssGroupModel
- from PIL import Image
- # 富文本编辑器
- class WebEditorContensModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = EditorContens
- fields = '__all__'
- class WebBarModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Bar
- fields = '__all__'
- class WebNavigationModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Navigation
- fields = '__all__'
- class WebCompanyModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Company
- fields = '__all__'
- class WebSlideshowModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Slideshow
- fields = '__all__'
- # def list(self, validated_data):
- # '''重写create方法实现,将密码加密后保存'''
- # print(validated_data)
- # # return Slideshow.objects.create(**validated_data)
- class WebHmweModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Hmwe
- fields = '__all__'
- class WebHmartModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Hmart
- fields = '__all__'
- class WebHmcaseModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Hmcase
- fields = '__all__'
- class WebColumnModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Column
- fields = '__all__'
- class WebHmgroupModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Hmgroup
- fields = '__all__'
- class WebHmaddressModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = Hmaddress
- fields = '__all__'
- class WnComponentSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = WnComponentModel
- fields = '__all__'
- class WnComponentCssSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = WnComponentCssModel
- fields = '__all__'
- class WnComponentKeyModelSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = WnComponentKeyModel
- fields = '__all__'
- def create(self, validated_data):
- # 查看最大排序值
- maxsort = WnComponentKeyModel.objects.aggregate(Max('sort'))['sort__max']
- print(maxsort)
- maxsort = maxsort if maxsort else 0
- maxsort = maxsort + 1
- validated_data['sort'] = maxsort
- return WnComponentKeyModel.objects.create(**validated_data)
- class WnComponentCssGroupSerializer(serializers.ModelSerializer):
- # haha = serializers.CharField(max_length=10,min_length=1,label="测试字段")
- class Meta:
- # 1,参考BookInfo,生成序列化器的字段
- model = WnComponentCssGroupModel
- fields = '__all__'
|