serializers.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from rest_framework import serializers
  2. from .models import ListModel
  3. from utils import datasolve
  4. from rest_framework.exceptions import ValidationError
  5. class GoodsGetSerializer(serializers.ModelSerializer):
  6. goods_code = serializers.CharField(read_only=True, required=False)
  7. goods_desc = serializers.CharField(read_only=True, required=False)
  8. goods_supplier = serializers.CharField(read_only=True, required=False)
  9. goods_weight = serializers.FloatField(read_only=True, required=False)
  10. goods_w = serializers.FloatField(read_only=True, required=False)
  11. goods_d = serializers.FloatField(read_only=True, required=False)
  12. goods_h = serializers.FloatField(read_only=True, required=False)
  13. unit_volume = serializers.FloatField(read_only=True, required=False)
  14. goods_unit = serializers.CharField(read_only=True, required=False)
  15. goods_class = serializers.CharField(read_only=True, required=False)
  16. goods_brand = serializers.CharField(read_only=True, required=False)
  17. goods_color = serializers.CharField(read_only=True, required=False)
  18. goods_shape = serializers.CharField(read_only=True, required=False)
  19. goods_specs = serializers.CharField(read_only=True, required=False)
  20. goods_origin = serializers.CharField(read_only=True, required=False)
  21. goods_cost = serializers.FloatField(read_only=True, required=False)
  22. goods_price = serializers.FloatField(read_only=True, required=False)
  23. creater = serializers.CharField(read_only=True, required=False)
  24. bar_code = serializers.CharField(read_only=True, required=False)
  25. create_time = serializers.DateTimeField(read_only=True, format='%Y-%m-%d %H:%M:%S')
  26. update_time = serializers.DateTimeField(read_only=True, format='%Y-%m-%d %H:%M:%S')
  27. class Meta:
  28. model = ListModel
  29. exclude = ['openid', 'is_delete', ]
  30. read_only_fields = ['id']
  31. class GoodsPostSerializer(serializers.ModelSerializer):
  32. openid = serializers.CharField(read_only=False, required=False, validators=[datasolve.openid_validate])
  33. goods_code = serializers.CharField(read_only=False, required=True, min_length=1,
  34. validators=[datasolve.data_validate])
  35. goods_desc = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  36. goods_supplier = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  37. goods_weight = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  38. goods_w = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  39. goods_d = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  40. goods_h = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  41. unit_volume = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  42. goods_unit = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  43. goods_class = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  44. goods_brand = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  45. goods_color = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  46. goods_shape = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  47. goods_specs = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  48. goods_origin = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  49. goods_cost = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  50. goods_price = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  51. creater = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  52. bar_code = serializers.CharField(read_only=False, required=True)
  53. class Meta:
  54. model = ListModel
  55. exclude = ['is_delete', ]
  56. read_only_fields = ['id', 'create_time', 'update_time', ]
  57. class GoodsUpdateSerializer(serializers.ModelSerializer):
  58. goods_code = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate],
  59. min_length=1)
  60. goods_desc = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  61. goods_supplier = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  62. goods_weight = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  63. goods_w = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  64. goods_d = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  65. goods_h = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  66. unit_volume = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  67. goods_unit = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  68. goods_class = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  69. goods_brand = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  70. goods_color = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  71. goods_shape = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  72. goods_specs = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  73. goods_origin = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  74. goods_cost = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  75. goods_price = serializers.FloatField(read_only=False, required=True, validators=[datasolve.data_validate])
  76. creater = serializers.CharField(read_only=False, required=True, validators=[datasolve.data_validate])
  77. bar_code = serializers.CharField(read_only=False, required=False)
  78. class Meta:
  79. model = ListModel
  80. exclude = ['openid', 'is_delete', ]
  81. read_only_fields = ['id', 'create_time', 'update_time', ]
  82. class GoodsPartialUpdateSerializer(serializers.ModelSerializer):
  83. goods_code = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate],
  84. min_length=1)
  85. goods_desc = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  86. goods_supplier = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  87. goods_weight = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  88. goods_w = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  89. goods_d = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  90. goods_h = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  91. unit_volume = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  92. goods_unit = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  93. goods_class = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  94. goods_brand = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  95. goods_color = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  96. goods_shape = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  97. goods_specs = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  98. goods_origin = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  99. goods_cost = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  100. goods_price = serializers.FloatField(read_only=False, required=False, validators=[datasolve.data_validate])
  101. creater = serializers.CharField(read_only=False, required=False, validators=[datasolve.data_validate])
  102. bar_code = serializers.CharField(read_only=False, required=False)
  103. class Meta:
  104. model = ListModel
  105. exclude = ['openid', 'is_delete', ]
  106. read_only_fields = ['id', 'create_time', 'update_time', ]
  107. class FileRenderSerializer(serializers.ModelSerializer):
  108. goods_code = serializers.CharField(read_only=False, required=False)
  109. goods_desc = serializers.CharField(read_only=False, required=False)
  110. goods_supplier = serializers.CharField(read_only=False, required=False)
  111. goods_weight = serializers.FloatField(read_only=False, required=False)
  112. goods_w = serializers.FloatField(read_only=False, required=False)
  113. goods_d = serializers.FloatField(read_only=False, required=False)
  114. goods_h = serializers.FloatField(read_only=False, required=False)
  115. unit_volume = serializers.FloatField(read_only=False, required=False)
  116. goods_unit = serializers.CharField(read_only=False, required=False)
  117. goods_class = serializers.CharField(read_only=False, required=False)
  118. goods_brand = serializers.CharField(read_only=False, required=False)
  119. goods_color = serializers.CharField(read_only=False, required=False)
  120. goods_shape = serializers.CharField(read_only=False, required=False)
  121. goods_specs = serializers.CharField(read_only=False, required=False)
  122. goods_origin = serializers.CharField(read_only=False, required=False)
  123. goods_cost = serializers.FloatField(read_only=False, required=False)
  124. goods_price = serializers.FloatField(read_only=False, required=False)
  125. creater = serializers.CharField(read_only=False, required=False)
  126. create_time = serializers.DateTimeField(read_only=True, format='%Y-%m-%d %H:%M:%S')
  127. update_time = serializers.DateTimeField(read_only=True, format='%Y-%m-%d %H:%M:%S')
  128. class Meta:
  129. model = ListModel
  130. ref_name = 'GOODSFileRenderSerializer'
  131. exclude = ['openid', 'is_delete', ]