serializers.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from django_filters import filters
  2. from rest_framework import serializers
  3. from .models import View_ydzpcjh,View_pcydscjh,view_tf_pos
  4. from django_filters.filterset import FilterSet
  5. from . import models
  6. # 月度主排产过滤设置
  7. class YdCourseFilterSet(FilterSet):
  8. # 区间过滤:field_name关联的Model字段;lookup_expr设置规则;gt是大于,gte是大于等于;
  9. min_pmc_dd = filters.DateTimeFilter(field_name='pmc_dd', lookup_expr='gt')
  10. max_pmc_dd = filters.DateTimeFilter(field_name='pmc_dd', lookup_expr='lt')
  11. class Meta:
  12. model = models.View_ydzpcjh
  13. fields = ['min_pmc_dd', 'max_pmc_dd', 'cus_no', 'so_no', 'mrp_no']
  14. # 月度主排产序列化器
  15. class YdzpcjhZserializer(serializers.ModelSerializer):
  16. class Meta:
  17. # jhscrq = serializers.CharField(max_length=40,label="计划上线生产日期")
  18. model = View_ydzpcjh
  19. fields = '__all__'
  20. # pc月度排产计划过滤设置
  21. class PcCourseFilterSet(FilterSet):
  22. # 区间过滤:field_name关联的Model字段;lookup_expr设置规则;gt是大于,gte是大于等于;
  23. min_pmc_dd = filters.DateTimeFilter(field_name='pmc_dd', lookup_expr='gt')
  24. max_pmc_dd = filters.DateTimeFilter(field_name='pmc_dd', lookup_expr='lt')
  25. class Meta:
  26. model = models.View_pcydscjh
  27. fields = ['min_pmc_dd', 'max_pmc_dd', 'cus_snm', 'so_no', 'mrp_no']
  28. # pc月度排产计划序列化器
  29. class PcydpcjhZserializer(serializers.ModelSerializer):
  30. class Meta:
  31. # jhscrq = serializers.CharField(max_length=40,label="计划上线生产日期")
  32. model = View_pcydscjh
  33. fields = '__all__'
  34. # 研磨品需求计划过滤设置
  35. class YmpCourseFilterSet(FilterSet):
  36. # 区间过滤:field_name关联的Model字段;lookup_expr设置规则;gt是大于,gte是大于等于;
  37. min_pmc_dd = filters.DateTimeFilter(field_name='pmc_dd', lookup_expr='gt')
  38. max_pmc_dd = filters.DateTimeFilter(field_name='pmc_dd', lookup_expr='lt')
  39. class Meta:
  40. model = models.view_tf_pos
  41. fields = ['min_pmc_dd', 'max_pmc_dd', 'so_no', 'mrp_no']
  42. # 研磨品需求计划序列化器
  43. class YmpdpcjhZserializer(serializers.ModelSerializer):
  44. class Meta:
  45. mo_no1 = serializers.CharField(max_length=40,label="制令单1")
  46. model = view_tf_pos
  47. fields = '__all__'
  48. # class View_tb_contentSerializer(serializers.ModelSerializer):
  49. # class Meta:
  50. # model = View_tb_content
  51. # # 全部字段
  52. # fields = '__all__'
  53. # #指定字段
  54. # # fields = ('title', 'url', 'text')
  55. # # 指明哪些字段不显示
  56. # # exclude = ('image',)
  57. # # 设置只读
  58. # read_only_fields = ('id','create_time','update_time','image','text','title','url')
  59. # # 增加约束
  60. # # extra_kwargs = {
  61. # # "bread": {
  62. # # "max_value": 10000,
  63. # # "min_value": 0
  64. # # },
  65. # # "bcomment": {
  66. # # "max_value": 99999,
  67. # # "min_value": 0
  68. # # },
  69. # # }
  70. # # 多字段校验
  71. # # def validate(self, attrs):
  72. # # title = attrs['title']
  73. # # print(title)
  74. # # if len(title)!=20:
  75. # # raise serializers.ValidationError('title标题不合法')
  76. # # # return http.JsonResponse({"aa":"bbbb"},safe=False)
  77. # # return attrs
  78. #