django-admin-data-from-external-service


Namedjango-admin-data-from-external-service JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/estin/django-admin-data-from-external-service
SummaryHelpers to extend Django Admin with data from external service with minimal hacks
upload_time2023-01-13 06:16:53
maintainer
docs_urlNone
authorEvgeniy Tatarkin
requires_python>=3.6,<4.0
licenseMIT
keywords django admin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<div align="center">
 <p><h1>django-admin-data-from-external-service</h1> </p>
  <p><strong>Helpers to extend Django Admin with data from external service with minimal hacks</strong></p>
  <p></p>
</div>

[Live demo](https://dadfes.herokuapp.com/) with [sources](https://github.com/estin/django-admin-data-from-external-service/tree/master/demo) on [Heroku](https://heroku.com) free quota (please be patient, it will take some time for the app to wake up)
 - [view](http://dadfes.herokuapp.com/github/repository/) Github repository of Django org ([sources](https://github.com/estin/django-admin-data-from-external-service/tree/master/demo/github/models.py)), may appear api rate limit error
 - [view](http://dadfes.herokuapp.com/clickhouse/recipe/) recipes from ClickHouse [playground](https://clickhouse.com/docs/en/getting-started/example-datasets/recipes/) ([sources](https://github.com/estin/django-admin-data-from-external-service/tree/master/demo/clickhouse/models.py))

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

```python
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](LICENSE) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/estin/django-admin-data-from-external-service",
    "name": "django-admin-data-from-external-service",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4.0",
    "maintainer_email": "",
    "keywords": "django,admin",
    "author": "Evgeniy Tatarkin",
    "author_email": "tatarkin.evg@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b5/1c/307e08dd5b0f8db104ca63a36d8c14ff06d28183a679c0146ecc14b64719/django_admin_data_from_external_service-0.1.2.tar.gz",
    "platform": null,
    "description": "\n<div align=\"center\">\n <p><h1>django-admin-data-from-external-service</h1> </p>\n  <p><strong>Helpers to extend Django Admin with data from external service with minimal hacks</strong></p>\n  <p></p>\n</div>\n\n[Live demo](https://dadfes.herokuapp.com/) with [sources](https://github.com/estin/django-admin-data-from-external-service/tree/master/demo) on [Heroku](https://heroku.com) free quota (please be patient, it will take some time for the app to wake up)\n - [view](http://dadfes.herokuapp.com/github/repository/) Github repository of Django org ([sources](https://github.com/estin/django-admin-data-from-external-service/tree/master/demo/github/models.py)), may appear api rate limit error\n - [view](http://dadfes.herokuapp.com/clickhouse/recipe/) recipes from ClickHouse [playground](https://clickhouse.com/docs/en/getting-started/example-datasets/recipes/) ([sources](https://github.com/estin/django-admin-data-from-external-service/tree/master/demo/clickhouse/models.py))\n\nMain features:\n - reuse Django Admin layout to simplify customization of viewing and managing external data (list/view/filter+search/ordering)\n - datasource agnostic\n - django2.x/django3.x/django4.x support\n\n## How it works\n\nUsed custom ChangeList to determine method to pull external data and mock paginator behaviour.\n\n## Example\n\n```python\nfrom django.db import models\nfrom django.contrib import admin\n\nfrom dadfes.admin import DfesAdminModelMixin\n\n\n# Declare model for external data (managed: false)\nclass ExternalUser(models.Model):\n    id = models.IntegerField(\"Id\", primary_key=True)\n    username = models.TextField(\"Username\")\n\n    class Meta:\n        managed = False\n        verbose_name = \"External User Model\"\n\n\n# 1. mixin DfesAdminModelMixin\nclass ExternalUserAdmin(DfesAdminModelMixin, admin.ModelAdmin):\n    list_display = (\n        \"id\",\n        \"username\",\n    )\n\n    # 2. and implement get_list method with returning\n    # `{\"total\": <total number or items>, \"items\": <list of ExternalUser instances>}`\n    def get_list(self, request, page_num, list_per_page):\n\n        # 2.1 pull data from some service, where\n        #   search = request.GET.get('q')\n        #   order_by = request.GET.get('o')\n        #   some_list_filter = request.GET.get('some_list_filter')\n        data =  {\n            'total': 1,\n            'users': [\n                {'id': 1, 'username': 'User1'},\n            ]\n        }\n\n        # 2.2 map data to model instances\n        items = [ExternalUser(**i) for i in data.get(\"users\") or []]\n\n        return {\n            \"total\": data.get(\"total\") or 0,\n            \"items\": items,\n        }\n\n    # 3. other standart django admin customization\n    def get_object(self, request, object_id, *args, **kwargs):\n        # 3.1 fetch object from external service\n        user = {'id': 1, 'username': 'User1'},\n        # 3.2 map data to model instance\n        return ExternalUser(**user)\n\nadmin.site.register(ExternalUser, ExternalUserAdmin)\n```\n\n## License\n\nThis project is licensed under\n\n* MIT license ([LICENSE](LICENSE) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Helpers to extend Django Admin with data from external service with minimal hacks",
    "version": "0.1.2",
    "split_keywords": [
        "django",
        "admin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5fa268bdcf280e48e4d74a2a13e5576dea6796a8ba64d93a5b01ca33987b96e9",
                "md5": "e4f7d7fd79bb110cdee02b3c157d8eaf",
                "sha256": "973e1c199152274fbf149372f1b24bbe214a958e8b0106f9bf181f7778d6cece"
            },
            "downloads": -1,
            "filename": "django_admin_data_from_external_service-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e4f7d7fd79bb110cdee02b3c157d8eaf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4.0",
            "size": 4860,
            "upload_time": "2023-01-13T06:16:51",
            "upload_time_iso_8601": "2023-01-13T06:16:51.903939Z",
            "url": "https://files.pythonhosted.org/packages/5f/a2/68bdcf280e48e4d74a2a13e5576dea6796a8ba64d93a5b01ca33987b96e9/django_admin_data_from_external_service-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b51c307e08dd5b0f8db104ca63a36d8c14ff06d28183a679c0146ecc14b64719",
                "md5": "d4261fcd86830759360acc74a45dc546",
                "sha256": "c56b11402e3b1a0a43a1365904ef27ddb4e7e196cb027b56cf296f6f4d999cfd"
            },
            "downloads": -1,
            "filename": "django_admin_data_from_external_service-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d4261fcd86830759360acc74a45dc546",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4.0",
            "size": 4562,
            "upload_time": "2023-01-13T06:16:53",
            "upload_time_iso_8601": "2023-01-13T06:16:53.713086Z",
            "url": "https://files.pythonhosted.org/packages/b5/1c/307e08dd5b0f8db104ca63a36d8c14ff06d28183a679c0146ecc14b64719/django_admin_data_from_external_service-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-13 06:16:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "estin",
    "github_project": "django-admin-data-from-external-service",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "django-admin-data-from-external-service"
}
        
Elapsed time: 0.03101s