Skip to content

Commit a7e7a3c

Browse files
committed
docs: Update README.md
1 parent 09ca7b9 commit a7e7a3c

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ Then add "easy" to your django INSTALLED_APPS:
4949
]
5050
```
5151

52-
53-
Get your admin api up and running:
52+
### Usage
53+
#### Get all your Django app CRUD APIs up and running
54+
In your Django project next to urls.py create new apis.py file:
5455
```
56+
from easy.main import EasyAPI
57+
5558
api_admin_v1 = EasyAPI(
5659
urls_namespace="admin_api",
5760
version="v1.0.0",
@@ -60,16 +63,58 @@ api_admin_v1 = EasyAPI(
6063
# Automatic Admin API generation
6164
api_admin_v1.auto_create_admin_controllers()
6265
```
66+
Now go to urls.py and add the following:
67+
```
68+
from django.urls import path
69+
from .apis import apis
70+
71+
urlpatterns = [
72+
path("admin/", admin.site.urls),
73+
path("api_admin/v1/", apis.urls), # <---------- !
74+
]
75+
```
76+
#### Interactive API docs
77+
Now go to http://127.0.0.1:8000/api_admin/v1/docs
78+
79+
You will see the automatic interactive API documentation (provided by Swagger UI).
80+
![Auto generated APIs List](https://github.com/freemindcore/django-api-framework/blob/fae8209a8d08c55daf75ac3a4619fe62b8ef3af6/docs/images/admin_apis_list.png)
6381

64-
Please check tests/demo_app for more.
82+
#### Adding CRUD APIs to a specific API Controller
83+
84+
By inheriting CrudAPIController class, CRUD APIs will be added to your API controller.
85+
Configuration is available via Meta class:
86+
- `model_exclude`: fields to be excluded in Schema
87+
- `model_fields`: fields to be included in Schema, default to `"__all__"`
88+
- `model_join`: prefetch and retrieve all m2m fields, default to False
89+
- `model_recursive`: recursively retrieve FK/OneToOne fields, default to False
90+
- `sensitive_fields`: fields to be ignored
91+
92+
93+
Example:
94+
```
95+
@api_controller("even_api", permissions=[AdminSitePermission])
96+
class EventAPIController(CrudAPIController):
97+
def __init__(self, service: EventService):
98+
super().__init__(service)
99+
100+
class Meta:
101+
model = Event # django model
102+
generate_crud = True # whether to create crud api, default to True
103+
model_fields = ["field_1", "field_2",] # if not configured default to "__all__"
104+
model_join = True
105+
model_recursive = True
106+
sensitive_fields = ["password", "sensitive_info"]
107+
108+
```
109+
Please check tests/demo_app for more examples.
65110

66111

67112
### Boilerplate Django project
68-
A boilerplate Django project for quickly getting started:
113+
A boilerplate Django project for quickly getting started, production ready easy-apis wiht 100% test coverage ready:
69114
https://github.com/freemindcore/django-easy-api
70115

71-
![Auto generated APIs List](https://github.com/freemindcore/django-api-framework/blob/fae8209a8d08c55daf75ac3a4619fe62b8ef3af6/docs/images/admin_apis_list.png)
72116
![Auto generated APIs - Users](https://github.com/freemindcore/django-api-framework/blob/9aa26e92b6fd79f4d9db422ec450fe62d4cd97b9/docs/images/user_admin_api.png)
73117
![Auto generated APIs - Schema](https://github.com/freemindcore/django-api-framework/blob/9aa26e92b6fd79f4d9db422ec450fe62d4cd97b9/docs/images/auto_api_demo_2.png)
74118

75-
_Note: this project is still in early stage, comments and advices are highly appreciated._
119+
### Thanks to your help
120+
**_If you find this project useful, please give your stars to support this open-source project. :) Thank you !_**

easy/controller/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class CrudAPIController(metaclass=CrudApiMetaclass):
2727
generate_crud: whether to create crud api, default to True
2828
model_exclude: fields to be excluded in Schema, it will ignore model_fields
2929
model_fields: fields to be included in Schema, default to "__all__"
30-
model_join: retrieve all m2m fields, default to True
31-
model_recursive: recursively retrieve FK/OneToOne models, default to False
30+
model_join: prefetch and retrieve all m2m fields, default to False
31+
model_recursive: recursively retrieve FK/OneToOne fields, default to False
3232
sensitive_fields: fields to be ignored
3333
3434
Example:

easy/permissions/adminsite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class AdminSitePermission(IsAdminUser):
1212
"""
13-
Allows delete only to super user, and change to only staff/super users.
13+
Only staff users with the right permission can modify objects.
1414
"""
1515

1616
def has_permission(

0 commit comments

Comments
 (0)