This repository demonstrates how to implement Role-Based Access Control (RBAC) using Django Rest Framework (DRF). It covers the creation of custom roles (admin, doctor, staff, patient) and object-level permissions, allowing fine-grained control over API endpoints. The project provides fully functional APIs for creating users, managing staff, and assigning permissions dynamically.
- Dynamic Role Management – Admin, Doctor, Staff, and Patient roles.
- Custom Permission Classes – Restrict API access based on user roles.
- Object-Level Permissions – Control access to specific objects (e.g., appointments).
- Token Authentication – Secure API endpoints with DRF’s token authentication.
- API Endpoints for Staff Management – Easily create staff and assign permissions dynamically.
- Permission Inheritance – Staff permissions are inherited from the doctor role they are linked to.
- Django Custom User Model
- DRF ViewSets and Actions
- Custom Permissions (
BasePermission) - One-to-One and Foreign Key Relationships
- Group and User Permissions with Django’s Built-in Auth
# Clone the repository
git clone https://github.com/boxabhi/Django-DRF-Custom-Roles-and-Permissions-Role-Based-Access-Control-RBAC-with-Django-Rest-Framework
# Navigate to the project directory
cd drf-custom-roles-permissions
# Create and activate virtual environment
python -m venv env
source env/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run migrations
python manage.py migrate
# Create a superuser
python manage.py createsuperuser
# Run the development server
python manage.py runserver
MIT License. Feel free to use this project in your applications.
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
For questions or collaborations, feel free to reach out via LinkedIn. https://www.linkedin.com/in/gupta-abhijeet/ https://www.instagram.com/_abhijeetgupta/reels/
Django DRF custom roles, DRF custom permissions, Django role-based access control, Django dynamic roles API, Django RBAC tutorial, DRF object-level permissions, Django Rest Framework custom auth, DRF admin doctor staff patient roles.