Create Custom Permissions
A snippet showing how to add custom permissions for Django models.
# models.py
from django.db import models
class Article(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
class Meta:
permissions = [
("can_publish", "Can publish articles"),
("can_archive", "Can archive articles"),
]
# Django Admin
1. Go to /admin/auth/group/
2. Select or create a group
3. Assign your custom permissions like:
- Can publish articles
- Can archive articles
Explanation:
-
You can define custom permissions inside the model's
Metaclass using thepermissionsattribute. - Each permission is a tuple with a codename and a human-readable label.
- These permissions appear in the Django admin and can be assigned to users or groups.
-
Use
user.has_perm('yourapp.can_publish')to check permissions in views.
- Category Authentication & Authorization
- Total Views 1113
- Last Modified 25 November, 2025
- Tags #permissions #authorization #auth #models
Previous snippet
Assign User to Group Automatically
Next snippet