Trippy Samurai
unread,May 26, 2022, 1:20:23 AM5/26/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
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)