A RESTful API implementation of django.contrib.admin, designed for writing custom frontends.
Project description
Django API Admin
A RESTful API implementation of django.contrib.admin, designed for writing custom frontends.
Report Bug
·
Request Feature
Table of Contents
About The Project
Django API Admin is a RESTful API implementation of the django.contrib.admin application, designed to make it easy to create custom frontends. This project aims to provide developers with a flexible API that mirrors the functionality of Django's built-in admin interface, allowing for seamless integration with modern web client interfaces.
Key Features:
- RESTful API: Offers a comprehensive API for managing Django models, enabling developers to build custom administrative interfaces.
- Custom Frontends: Designed to support the development of tailored frontends that meet specific project requirements.
- Extensible and Modular: Build with the same
django.contrib.adminAPI, allowing for easy customization and integration with existing Django projects.
The project is continuously evolving, with new features and improvements being added regularly. Contributions from the community are highly encouraged to help expand and enhance the capabilities of this tool.
To get started, follow the installation and usage instructions provided in this README. Whether you're building a new project or integrating with an existing one, Django API Admin offers the flexibility and power you need to manage your application's data effectively.
Built With
This section should list any major frameworks/libraries used to bootstrap your project. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
Getting Started
To set up the project locally, follow these steps:
Prerequisites
Before you begin, ensure you have met the following requirements:
-
Python 3.12+: Make sure Python is installed on your machine. You can download it from python.org.
-
Django REST framework
pip install djangorestframework
-
drf-spectacular
pip install drf-spectacular
Installation
This section will walk you through the steps to install django-api-admin in your Django project. Follow these instructions to get started.
- Install the Package
pip install django-api-admin
- Add to Installed Apps Add django_api_admin and it's requirements to the INSTALLED_APPS list in your Django project's settings.py file (the order doesn't matter):
# settings.py INSTALLED_APPS = [ 'corsheaders', 'drf_spectacular', 'rest_framework', 'django_api_admin' ]
- In your Django settings file, add or update the
REST_FRAMEWORKdictionary to include the drf spectacular as the DEFAULT_SCHEMA_CLASS:# settings.py REST_FRAMEWORK = { 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', }
- Add the modify_schema hook to improve the auto generated openAPI schema
# settings.py SPECTACULAR_SETTINGS = { "POSTPROCESSING_HOOKS": [ 'drf_spectacular.hooks.postprocess_schema_enums', 'django_api_admin.hooks.modify_schema' ] }
Thats it you are now ready to register your models and implement your django admin frontend!
CORS Configuration
If you plan to build a custom frontend in React.js or Vue.js then you might want to consider adding CORS configuration to your Django project. This will allow your frontend to make requests to your Django backend.
- Install django-cors-headers package
pip install django-cors-headers
-
Add
corsheaderstoINSTALLED_APPSin your Django project's settings.py file (the order doesn't matter):# settings.py INSTALLED_APPS = [ 'corsheaders', # ... ]
-
Add the urls of your client side applications to the
CORS_ORIGIN_WHITELIST# settings.py CORS_ORIGIN_WHITELIST = ( 'http://localhost', # jest-dom test server 'http://localhost:3000', # react development server ) CORS_ALLOW_CREDENTIALS = True
Your client side application should now be able to make requests to your django backend!
Authentication
Unlike django.contrib.admin this package doesn't include it's own authentication functionality. You will need implement authentication on your own, however the django-api-admin makes it very easy to add support for authentication frameworks that support rest_framework. This is how you can add django-allauth for instance:
- Install
django-allauth
pip install django-allauth
- Configure
django-allauthsettings for your project
# settings.py
INSTALLED_APPS = [
# ...
'allauth',
]
MIDDLEWARE = [
# ...
'allauth.account.middleware.AccountMiddleware',
# ...
]
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
- Add the
authentication_classesto anAPIAdminSitesubclass.
from django_api_admin import APIAdminSite
class AdminSite(APIAdminSite):
def get_authentication_classes(self):
from allauth.headless.contrib.rest_framework.authentication import XSessionTokenAuthentication
return [XSessionTokenAuthentication, authentication.SessionAuthentication]
site = AdminSite()
- include the
django-allauthheadless urls in yoururls.pyfile.
# urls.py
urlpatterns = [
# ...
path("_allauth/", include("allauth.headless.urls")),
]
Now, django-api-admin will use the provided authentication_classes for authenticating users.
Usage
This section provides a simple example on how to use django-api-admin. If you're setting up for the first time, follow the example below to get started.
- Create some models
# models.py from django.db import models class Author(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name class Book(models.Model): title = models.CharField(max_length=100) author = models.ForeignKey(Author, on_delete=models.CASCADE) def __str__(self): return self.title
- Register them using the admin site
# admin.py from django_api_admin.sites import site from .models import Author, Book site.register(Author) site.register(Book)
- Include URLs Include the django-api-admin URLs in your
# urls.py from django.urls import path from django_api_admin.sites import site # the admin site needs to know the name of the url prefix in this case "admin/" # the default is just the admin site's name which is "admin" + "/" # for the default admin site urlpatterns = [ path('admin/', site.urls), ]
Roadmap
- Rewrite django.contrib.admin as an API
- Add support for Bulk Actions
- Add OpenAPI documentation
- Add support for charts
- Add support for global full-text search
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Top Contributors
License
Distributed under the MIT License. See the LICENSE file for more information.
Contact
Muhammad Salah - @daemobixia - msbizzaccount@gmail.com
Project Link: https://github.com/demon-bixia/django-api-admin
Acknowledgments
This section is dedicated to recognizing the valuable resources and contributions that have supported this project. Below are some of the key references and inspirations that have been instrumental in the project's development journey.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_api_admin-1.3.0.tar.gz.
File metadata
- Download URL: django_api_admin-1.3.0.tar.gz
- Upload date:
- Size: 601.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd6c841fe4bcc4f4c67f0e4c059bb1801504db0a7d5f48cca6f8f738cb81334c
|
|
| MD5 |
a87b1f92db66a0f95f23c10255f421f8
|
|
| BLAKE2b-256 |
feb8eb5d17dac3be3d8217092c12f3155af5a6d8e2bff57ed1d305600b4ecdb2
|
Provenance
The following attestation bundles were made for django_api_admin-1.3.0.tar.gz:
Publisher:
python-publish.yml on daemon-bixia/django-api-admin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_api_admin-1.3.0.tar.gz -
Subject digest:
dd6c841fe4bcc4f4c67f0e4c059bb1801504db0a7d5f48cca6f8f738cb81334c - Sigstore transparency entry: 1710095122
- Sigstore integration time:
-
Permalink:
daemon-bixia/django-api-admin@b552e149c22666bfff508542f41954a4d565f0cf -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/daemon-bixia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b552e149c22666bfff508542f41954a4d565f0cf -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_api_admin-1.3.0-py3-none-any.whl.
File metadata
- Download URL: django_api_admin-1.3.0-py3-none-any.whl
- Upload date:
- Size: 124.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92a92a6fca32018dc6619fcce92d2c5aec1aaaadc3d7f8311ef7b3992f4eba97
|
|
| MD5 |
10c9ff80011c2286733da29e30c2a562
|
|
| BLAKE2b-256 |
df6e268eac70907ae7992c3d75bb5b4cf6c63332c615775cad97ef8be1af3cb7
|
Provenance
The following attestation bundles were made for django_api_admin-1.3.0-py3-none-any.whl:
Publisher:
python-publish.yml on daemon-bixia/django-api-admin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_api_admin-1.3.0-py3-none-any.whl -
Subject digest:
92a92a6fca32018dc6619fcce92d2c5aec1aaaadc3d7f8311ef7b3992f4eba97 - Sigstore transparency entry: 1710095163
- Sigstore integration time:
-
Permalink:
daemon-bixia/django-api-admin@b552e149c22666bfff508542f41954a4d565f0cf -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/daemon-bixia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b552e149c22666bfff508542f41954a4d565f0cf -
Trigger Event:
release
-
Statement type: