feat: myschedule createserializer 优化2
This commit is contained in:
parent
4739124cc8
commit
d83b5ec0d2
|
@ -429,14 +429,13 @@ class MyScheduleCreateSerializer(CustomModelSerializer):
|
|||
model = MySchedule
|
||||
fields = ['type', 'interval_', 'crontab_']
|
||||
|
||||
def validate(self, attrs):
|
||||
if attrs['type'] == 10 and attrs.get('interval_', None):
|
||||
attrs.pop('crontab_')
|
||||
elif attrs['type'] == 20 and attrs.get('crontab_', None):
|
||||
attrs.pop('interval_')
|
||||
else:
|
||||
raise ValidationError('信息有误')
|
||||
return super().validate(attrs)
|
||||
def to_internal_value(self, data):
|
||||
type = data.get('type', 10)
|
||||
if type == 10:
|
||||
data.pop('crontab_', None)
|
||||
elif type == 20:
|
||||
data.pop('interval_', None)
|
||||
return super().to_internal_value(data)
|
||||
|
||||
|
||||
class MyScheduleSerializer(CustomModelSerializer):
|
||||
|
|
|
@ -703,7 +703,6 @@ class MyScheduleViewSet(ListModelMixin, CreateModelMixin, DestroyModelMixin, Cus
|
|||
def get_chinese_description(self, type: str = 'interval', data: dict = {}):
|
||||
"""转换为汉语描述
|
||||
"""
|
||||
print(data)
|
||||
if type == 'interval':
|
||||
return f"每隔{data['every']}{self.period_dict[data['period']]}"
|
||||
elif type == 'crontab':
|
||||
|
|
Loading…
Reference in New Issue