@@ -63,7 +63,7 @@ api_admin_v1 = EasyAPI(
6363# Automatic Admin API generation
6464api_admin_v1.auto_create_admin_controllers()
6565```
66- Now go to urls.py and add the following:
66+ Go to urls.py and add the following:
6767```
6868from django.urls import path
6969from .apis import api_admin_v1
@@ -78,16 +78,36 @@ Now go to http://127.0.0.1:8000/api_admin/v1/docs
7878You will see the automatic interactive API documentation (provided by Swagger UI).
7979![ Auto generated APIs List] ( https://github.com/freemindcore/django-api-framework/blob/fae8209a8d08c55daf75ac3a4619fe62b8ef3af6/docs/images/admin_apis_list.png )
8080
81- #### Adding CRUD APIs to a specific API Controller
81+ #### Auto generation configuration
82+ If AUTO_ADMIN_ENABLED_ALL_APPS is set to True (default), all app models CRUD apis will be generated.
83+ Apps in the AUTO_ADMIN_EXCLUDE_APPS list, will be always excluded.
8284
83- By inheriting CrudAPIController class, CRUD APIs will be added to your API controller.
84- Configuration is available via Meta class:
85+ If AUTO_ADMIN_ENABLED_ALL_APPS is set to False, only apps in the AUTO_ADMIN_INCLUDE_APPS list will have CRUD apis generated.
86+
87+ Also, configuration is possible for each model, via ApiMeta class:
88+ - ` generate_crud ` : whether to create crud api, default to True
8589- ` model_exclude ` : fields to be excluded in Schema
8690- ` model_fields ` : fields to be included in Schema, default to ` "__all__" `
8791- ` model_join ` : prefetch and retrieve all m2m fields, default to False
8892- ` model_recursive ` : recursively retrieve FK/OneToOne fields, default to False
8993- ` sensitive_fields ` : fields to be ignored
9094
95+ ```
96+ class Category(TestBaseModel):
97+ title = models.CharField(max_length=100)
98+ status = models.PositiveSmallIntegerField(default=1, null=True)
99+
100+ class ApiMeta:
101+ generate_crud = True
102+ model_fields = ["field_1", "field_2",] # if not configured default to "__all__"
103+ model_join = True
104+ model_recursive = True
105+ sensitive_fields = ["password", "sensitive_info"]
106+ ```
107+
108+ ### Adding CRUD APIs to a specific API Controller
109+ By inheriting CrudAPIController class, CRUD APIs can be added to any API controller.
110+ Configuration is available via Meta inner class in your Controller, same as the above ApiMeta inner class defined in your Django models.
91111
92112Example:
93113```
0 commit comments