Reputation: 1316
So, suppose that this is my model:
class Project(models.Model):
STATUS_NEW = 1
STATUS_VERIFICATION = 2
STATUS_ACCEPTED = 3
STATUS_CHOICES = (
(STATUS_NEW, _('New')),
(STATUS_VERIFICATION, _('Ready for verification')),
(STATUS_ACCEPTED, _('Accepted')),
)
status = models.PositiveSmallIntegerField(_('Status'), choices=STATUS_CHOICES, default=STATUS_NEW)
What would be the best way to implement field permissions so that user can change Project status from 1(new) to 2(ready for verification), but can't change its status to 3(accepted)?
Upvotes: 2
Views: 631
Reputation: 7386
Take a look at the serializer validation docs. If you implement a validate_status
method in your serializer you can add the logic there.
I hope that helps.
Upvotes: 1