class ProcessTaskSerializer(serializers.HyperlinkedModelSerializer): name = serializers.ChoiceField(choices=available_tasks(), ) responsible = serializers.SlugRelatedField(slug_field='username', read_only=True) class Meta: model = ProcessTask fields = ( 'url', 'id', 'name', 'status', 'progress', 'processstep', 'processstep_pos', 'time_started', 'time_done', 'undone', 'undo_type', 'retried', 'responsible', 'hidden', ) read_only_fields = ( 'status', 'progress', 'time_started', 'time_done', 'undone', 'undo_type', 'retried', 'hidden', )
def clean(self): """ Validates the task """ full_task_names = [k for k, v in available_tasks()] # Make sure that the task exists if self.name not in full_task_names: raise ValidationError("Task '%s' does not exist." % self.name)