Today we are going through on permission of the Django REST Framework. In the Django rest framework, there is 2 types of permission.
- Built-in permission
- Custom permission.
In this part of the article, we talk about custom permission. Suppose you have a model named
song and it has several fields like below.
from django.db import models class Song(models.Model): title = models.CharField(max_length=100) parentId = models.CharField(max_length=200) spectogram_text = models.TextField() harmonic_text = models.TextField() texture = models.TextField() pathname = models.CharField(max_length=100)
We will create a CRUD system where we impose some permission like below:
- All song is displayed logged in user.
- Superusers can delete a song.
- the owner can update the song
- Any logged-in user can add a new song.