dj-rest-admin


Namedj-rest-admin JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummaryA package to generate CRUD endpoints for registered models with the Django-REST Framework.
upload_time2023-05-04 20:53:50
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Dario Fragas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords django python django-rest-framework admin api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # This is a fork of [BdVade/DRF-admin](https://github.com/BdVade/DRF-admin) project

This repo has been renamed in order to avoid confusions with BdVade/DRF-admin and will be
mantained by myself. 

Any contribution and feature requests are welcome!

# dj-rest-admin
A package to generate CRUD endpoints for registered models with the Django-REST Framework. 

## Requirements
- [Django](https://docs.djangoproject.com/en/4.0/)
- [Django Rest Framework](https://www.django-rest-framework.org/)

## Installation
To install run:

`pip install drf-admin`

## Usage
- Add rest_admin.py in your app dirs for defining RestModelAdmin
- Import dj_rest_admin in the rest_admin.py 
- Call `dj_rest_admin.site.register(Model)` Model being the model to register 
- Add rest admin to your urls.py file.
- [Optional] Add `dj_rest_admin` to your `INSTALLED_APPS` for admin autodiscover.

## Prerequisite
- rest_framework should be properly set up to use this package hitch free

A sample of it's configuration in the settings file:
```python
 REST_FRAMEWORK={
            'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
            'TEST_REQUEST_RENDERER_CLASSES': [
                'rest_framework.renderers.MultiPartRenderer',
                'rest_framework.renderers.JSONRenderer',
                'rest_framework.renderers.TemplateHTMLRenderer', ],
            "DEFAULT_AUTHENTICATION_CLASSES": [
                'rest_framework.authentication.SessionAuthentication',
                'rest_framework.authentication.BasicAuthentication'
            ],
            "DEFAULT_PERMISSION_CLASSES": [
                'rest_framework.permissions.AllowAny',
            ]
        }
```

For example: 

models.py
```python
from django.db import models

class TestModel(models.Model):
    age = models.IntegerField()
```

admin.py
```python
from .models import TestModel
import dj_rest_admin

dj_rest_admin.site.register(TestModel)
```
urls.py
```python
from restadmin import site
from django.urls import path




urlpatterns = [
    ...
    path('restadmin/', site.urls),
    ...
]
```

## Customization
This package allows you to specify the following when registering your model
- `serializer_or_modeladmin`: A Model Serializer Class or a subclass of `RestModelAdmin`
- ` permission_classes`: A list of Permission classes
- `pagination_classs`: A Pagination Class

An example of how a call to the register method with all 3 would look is :
```python
dj_rest_admin.site.register(TestModel, serializer_or_modeladmin=AdminSerializer, permission_classes=[ReadOnly], 
                        pagination_class=LargeResultsSetPagination)

```

`RestModelAdmin` expose the same interface as `ModelViewSet` so you can add the whole customizations that
`ModelViewSet` offers. This includes:

- Custom querysets
- redifining defaults methods
- add actions as ModelViewSet's exta actions

You can also register models with the `register` decorator

Example:
```python
from dj_rest_admin import register, RestModelAdmin
from .models import TestModel

@register(TestModel)
class TestRestModelAdmin(RestModelAdmin):

    serializer_class = MyCustomSerializer # Optional. A default is provided if None defined

    def get_queryset(self):
        queryset = TestModel.objects.filter(age__lt=30)
        return queryset

```

## Endpoint Documentation
* This requires you to have coreapi installed

A page to document the Endpoints generated can be accessed by adding the following to your base urls file

```python
from dj_rest_admin import site


urlpatterns = [
   ...
    path('restadmin-docs/', site.docs)
    ...
]
```


Using this would require you to have your default schema Class set in your REST_FRAMEWORK config in your settings.py file
E.g

```
REST_FRAMEWORK = { 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }
```
Run your server and you can find the documentation at ` http://127.0.0.1:8000/restadmin-docs`
NOTE: The Documentation page is restricted to staff only(is_staff has to be True)
## Tests
To run the tests:

From the base directory run :
```
python load_tests.py
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "dj-rest-admin",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "django,python,django-rest-framework,admin,api",
    "author": "",
    "author_email": "Dario Fragas <dariofg98@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/cc/6e/1a83ad0bdae7cdae1a92b8bde41823aae032c251e2cf38f845910bd896f1/dj-rest-admin-1.0.2.tar.gz",
    "platform": null,
    "description": "# This is a fork of [BdVade/DRF-admin](https://github.com/BdVade/DRF-admin) project\n\nThis repo has been renamed in order to avoid confusions with BdVade/DRF-admin and will be\nmantained by myself. \n\nAny contribution and feature requests are welcome!\n\n# dj-rest-admin\nA package to generate CRUD endpoints for registered models with the Django-REST Framework. \n\n## Requirements\n- [Django](https://docs.djangoproject.com/en/4.0/)\n- [Django Rest Framework](https://www.django-rest-framework.org/)\n\n## Installation\nTo install run:\n\n`pip install drf-admin`\n\n## Usage\n- Add rest_admin.py in your app dirs for defining RestModelAdmin\n- Import dj_rest_admin in the rest_admin.py \n- Call `dj_rest_admin.site.register(Model)` Model being the model to register \n- Add rest admin to your urls.py file.\n- [Optional] Add `dj_rest_admin` to your `INSTALLED_APPS` for admin autodiscover.\n\n## Prerequisite\n- rest_framework should be properly set up to use this package hitch free\n\nA sample of it's configuration in the settings file:\n```python\n REST_FRAMEWORK={\n            'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',\n            'TEST_REQUEST_RENDERER_CLASSES': [\n                'rest_framework.renderers.MultiPartRenderer',\n                'rest_framework.renderers.JSONRenderer',\n                'rest_framework.renderers.TemplateHTMLRenderer', ],\n            \"DEFAULT_AUTHENTICATION_CLASSES\": [\n                'rest_framework.authentication.SessionAuthentication',\n                'rest_framework.authentication.BasicAuthentication'\n            ],\n            \"DEFAULT_PERMISSION_CLASSES\": [\n                'rest_framework.permissions.AllowAny',\n            ]\n        }\n```\n\nFor example: \n\nmodels.py\n```python\nfrom django.db import models\n\nclass TestModel(models.Model):\n    age = models.IntegerField()\n```\n\nadmin.py\n```python\nfrom .models import TestModel\nimport dj_rest_admin\n\ndj_rest_admin.site.register(TestModel)\n```\nurls.py\n```python\nfrom restadmin import site\nfrom django.urls import path\n\n\n\n\nurlpatterns = [\n    ...\n    path('restadmin/', site.urls),\n    ...\n]\n```\n\n## Customization\nThis package allows you to specify the following when registering your model\n- `serializer_or_modeladmin`: A Model Serializer Class or a subclass of `RestModelAdmin`\n- ` permission_classes`: A list of Permission classes\n- `pagination_classs`: A Pagination Class\n\nAn example of how a call to the register method with all 3 would look is :\n```python\ndj_rest_admin.site.register(TestModel, serializer_or_modeladmin=AdminSerializer, permission_classes=[ReadOnly], \n                        pagination_class=LargeResultsSetPagination)\n\n```\n\n`RestModelAdmin` expose the same interface as `ModelViewSet` so you can add the whole customizations that\n`ModelViewSet` offers. This includes:\n\n- Custom querysets\n- redifining defaults methods\n- add actions as ModelViewSet's exta actions\n\nYou can also register models with the `register` decorator\n\nExample:\n```python\nfrom dj_rest_admin import register, RestModelAdmin\nfrom .models import TestModel\n\n@register(TestModel)\nclass TestRestModelAdmin(RestModelAdmin):\n\n    serializer_class = MyCustomSerializer # Optional. A default is provided if None defined\n\n    def get_queryset(self):\n        queryset = TestModel.objects.filter(age__lt=30)\n        return queryset\n\n```\n\n## Endpoint Documentation\n* This requires you to have coreapi installed\n\nA page to document the Endpoints generated can be accessed by adding the following to your base urls file\n\n```python\nfrom dj_rest_admin import site\n\n\nurlpatterns = [\n   ...\n    path('restadmin-docs/', site.docs)\n    ...\n]\n```\n\n\nUsing this would require you to have your default schema Class set in your REST_FRAMEWORK config in your settings.py file\nE.g\n\n```\nREST_FRAMEWORK = { 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }\n```\nRun your server and you can find the documentation at ` http://127.0.0.1:8000/restadmin-docs`\nNOTE: The Documentation page is restricted to staff only(is_staff has to be True)\n## Tests\nTo run the tests:\n\nFrom the base directory run :\n```\npython load_tests.py\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Dario Fragas  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A package to generate CRUD endpoints for registered models with the Django-REST Framework.",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/dfg-98/dj-rest-admin"
    },
    "split_keywords": [
        "django",
        "python",
        "django-rest-framework",
        "admin",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd5db6dfe5a258bd03d1f1ff6fd335799d470e48dd2a2b671cee42a9acda3f69",
                "md5": "78b872cfc378ec6c03f5cc3b306fac83",
                "sha256": "4a4cf1877727a32781878f9672c34559f1a2633e8bf2eab7ff4ff0b7140be633"
            },
            "downloads": -1,
            "filename": "dj_rest_admin-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "78b872cfc378ec6c03f5cc3b306fac83",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8051,
            "upload_time": "2023-05-04T20:53:46",
            "upload_time_iso_8601": "2023-05-04T20:53:46.939742Z",
            "url": "https://files.pythonhosted.org/packages/cd/5d/b6dfe5a258bd03d1f1ff6fd335799d470e48dd2a2b671cee42a9acda3f69/dj_rest_admin-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc6e1a83ad0bdae7cdae1a92b8bde41823aae032c251e2cf38f845910bd896f1",
                "md5": "ef3603bad5af398510091eace44cb7b6",
                "sha256": "f1ed56ae0186fc75a9c4d1b8e303ced4c75476db965cd0711eecefb3ed703f0f"
            },
            "downloads": -1,
            "filename": "dj-rest-admin-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ef3603bad5af398510091eace44cb7b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8880,
            "upload_time": "2023-05-04T20:53:50",
            "upload_time_iso_8601": "2023-05-04T20:53:50.197327Z",
            "url": "https://files.pythonhosted.org/packages/cc/6e/1a83ad0bdae7cdae1a92b8bde41823aae032c251e2cf38f845910bd896f1/dj-rest-admin-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-04 20:53:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dfg-98",
    "github_project": "dj-rest-admin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "dj-rest-admin"
}
        
Elapsed time: 0.06088s