I need to allow a certain user, who is specified in the model, to modify a few of the model's fields. I know I need to create a permission class, which will control the whole process, but I have no idea how to do that. Here's the code sample:
class Task(models.Model):
creator = models.ForeignKey('auth.User', related_name='created_tasks', on_delete=models.CASCADE)
target = models.ForeignKey(User, related_name='assigned_tasks', on_delete=models.CASCADE)
title = models.CharField(max_length=100)
description = models.TextField()
created = models.DateTimeField(auto_now_add=True)
deadline = models.DateTimeField()
priority = models.CharField(max_length=50, choices=PRIORITY_CHOICES, default='NORMAL')
progress = models.CharField(max_length=50, choices=PROGRESS_CHOICES, default='ASSIGNED')
is_finished = models.BooleanField(default=False)
So I want to allow the target, to modify only progress and is_finished fields.
I am using DjangoRestFramework, not sure if that will help. Should I create a method, which will check if user == target, and ignore all the other changes or is it possible to create a permission which will do that.