I have a project in Django REST framework with model like this
class Attachment
attachment_type = models.PositiveSmallIntegerField(choices=constants.AttachmentTypes.CHOICES)
creator = models.ForeignKey(User, related_name="attachments", on_delete=models.PROTECT)
file = models.FileField(upload_to='uploads/%Y/%m/%d/', max_length=511)
name = models.CharField(max_length=255)
size = models.CharField(max_length=30)
And ModelViewSet using the model with custom permissions
class AttachmentViewSet(viewsets.ModelViewSet):
queryset = models.Attachment.objects.all()
Permissions for this ViewSet are based on a user roles and work fine. Problem is with permissions to a file field. It is now accessible to whoever has the link. I need the same permissions to a file as to Attachment endpoint.
What is the proper way to do it?