django-admin-data-from-external-service
Helpers to extend Django Admin with data from external service with minimal hacks
Live demo with sources on Heroku free quota (please be patient, it will take some time for the app to wake up)
- view Github repository of Django org (sources), may appear api rate limit error
- view recipes from ClickHouse playground (sources)
Main features:
- reuse Django Admin layout to simplify customization of viewing and managing external data (list/view/filter+search/ordering)
- datasource agnostic
- django2.x/django3.x/django4.x support
How it works
Used custom ChangeList to determine method to pull external data and mock paginator behaviour.
Example
from django.db import models
from django.contrib import admin
from dadfes.admin import DfesAdminModelMixin
# Declare model for external data (managed: false)
class ExternalUser(models.Model):
id = models.IntegerField("Id", primary_key=True)
username = models.TextField("Username")
class Meta:
managed = False
verbose_name = "External User Model"
# 1. mixin DfesAdminModelMixin
class ExternalUserAdmin(DfesAdminModelMixin, admin.ModelAdmin):
list_display = (
"id",
"username",
)
# 2. and implement get_list method with returning
# `{"total": <total number or items>, "items": <list of ExternalUser instances>}`
def get_list(self, request, page_num, list_per_page):
# 2.1 pull data from some service, where
# search = request.GET.get('q')
# order_by = request.GET.get('o')
# some_list_filter = request.GET.get('some_list_filter')
data = {
'total': 1,
'users': [
{'id': 1, 'username': 'User1'},
]
}
# 2.2 map data to model instances
items = [ExternalUser(**i) for i in data.get("users") or []]
return {
"total": data.get("total") or 0,
"items": items,
}
# 3. other standart django admin customization
def get_object(self, request, object_id, *args, **kwargs):
# 3.1 fetch object from external service
user = {'id': 1, 'username': 'User1'},
# 3.2 map data to model instance
return ExternalUser(**user)
admin.site.register(ExternalUser, ExternalUserAdmin)
License
This project is licensed under
- MIT license (LICENSE or http://opensource.org/licenses/MIT)
Metadata
Release files for django-admin-data-from-external-service 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_admin_data_from_external_service-0.1.2.tar.gz | 4.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_admin_data_from_external_service-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / django_admin_data_from_external_service-0.1.2.tar.gz
| Download URL | django_admin_data_from_external_service-0.1.2.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c56b11402e3b1a0a43a1365904ef27ddb4e7e196cb027b56cf296f6f4d999cfd
|
|
BLAKE2b-256 checksum How to use checksums |
b51c307e08dd5b0f8db104ca63a36d8c14ff06d28183a679c0146ecc14b64719
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.9 Linux/6.1.4-arch1-1
|
Release files / django_admin_data_from_external_service-0.1.2-py3-none-any.whl
| Download URL | django_admin_data_from_external_service-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
973e1c199152274fbf149372f1b24bbe214a958e8b0106f9bf181f7778d6cece
|
|
BLAKE2b-256 checksum How to use checksums |
5fa268bdcf280e48e4d74a2a13e5576dea6796a8ba64d93a5b01ca33987b96e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.9 Linux/6.1.4-arch1-1
|
Security for django-admin-data-from-external-service 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.