I have my Django website where i can have tasks created and subtasks under 
tasks i have mark complete option which is working fine i need them to be 
completed in batch like selecting multiple tasks at once and complete them.

**serializers.py**:

    class TaskCompleteSerializer(serializers.ModelSerializer):
         class Meta:
        model = Task
        fields = (
            'is_done',
        )

         def update(self, instance, validated_data):
             person = self.context['request'].user.person

             task_is_done = validated_data.get('is_done', False)

             if task_is_done:
                instance.subtasks.update(is_done=True)

             instance.is_done = task_is_done
             instance.done_by.set([person])
             instance.save()

             return instance

**views.py**:

    class TaskUpdateAPIView(UpdateAPIView):
         permission_classes = " "
         serializer_class = TaskCompleteSerializer
         queryset = Task.objects.all()
         model = Task
         lookup_url_kwarg = 'task_id'

**urls.py**

    path('<int:task_id>/complete/',views.TaskUpdateAPIView.as_view(), 
    name='task_update'),

**models.py**

    class Task(BaseModel):
        name = models.CharField(max_length=255)
        done_by = models.ManyToManyField(
        User,
        related_name='tasks_completed',
        blank=True,
        )
        is_done = models.BooleanField(default=False)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/331763ee-17f4-4713-8d26-884696413328n%40googlegroups.com.

Reply via email to