Skip to content

Commit 73294d0

Browse files
committed
refactor: Meta -> APIMeta
1 parent 0eaf9b1 commit 73294d0

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Apps in the `CRUD_API_EXCLUDE_APPS` list, will be always excluded.
8888

8989
If `CRUD_API_ENABLED_ALL_APPS` is set to False, only apps in the `CRUD_API_INCLUDE_APPS` list will have CRUD apis generated.
9090

91-
Also, configuration is possible for each model, via ApiMeta class:
91+
Also, configuration is possible for each model, via APIMeta class:
9292
- `generate_crud`: whether to create crud api, default to True
9393
- `model_exclude`: fields to be excluded in Schema
9494
- `model_fields`: fields to be included in Schema, default to `"__all__"`
@@ -102,7 +102,7 @@ class Category(TestBaseModel):
102102
title = models.CharField(max_length=100)
103103
status = models.PositiveSmallIntegerField(default=1, null=True)
104104
105-
class ApiMeta:
105+
class APIMeta:
106106
generate_crud = True
107107
model_fields = ["field_1", "field_2",] # if not configured default to "__all__"
108108
model_join = True
@@ -112,7 +112,7 @@ class Category(TestBaseModel):
112112

113113
### Adding CRUD APIs to a specific API Controller
114114
By inheriting `CrudAPIController` class, CRUD APIs can be added to any API controller.
115-
Configuration is available via `Meta` inner class in your Controller, same as the above `ApiMeta` inner class defined in your Django models.
115+
Configuration is available via `APIMeta` inner class in your Controller, same as the above `APIMeta` inner class defined in your Django models.
116116

117117
Example:
118118

@@ -122,7 +122,7 @@ class EventAPIController(CrudAPIController):
122122
def __init__(self, service: EventService):
123123
super().__init__(service)
124124
125-
class Meta:
125+
class APIMeta:
126126
model = Event # django model
127127
generate_crud = True # whether to create crud api, default to True
128128
model_fields = ["field_1", "field_2",] # if not configured default to "__all__"

easy/controller/auto_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def create_api_controller(
3030
model_name = model.__name__ # type:ignore
3131

3232
model_opts: ModelOptions = ModelOptions.get_model_options(
33-
getattr(model, "ApiMeta", None)
33+
getattr(model, "APIMeta", None)
3434
)
3535

36-
Meta = type(
37-
"Meta",
36+
APIMeta = type(
37+
"APIMeta",
3838
(object,),
3939
{
4040
"model": model,
@@ -54,7 +54,7 @@ def create_api_controller(
5454
class_name,
5555
(CrudAPIController,),
5656
{
57-
"Meta": Meta,
57+
"APIMeta": APIMeta,
5858
},
5959
)
6060

easy/controller/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import logging
22

3-
from easy.controller.meta import CrudApiMetaclass
3+
from easy.controller.meta import CrudAPIMetaclass
44

55
logger = logging.getLogger(__name__)
66

77

8-
class CrudAPIController(metaclass=CrudApiMetaclass):
8+
class CrudAPIController(metaclass=CrudAPIMetaclass):
99
"""
10-
Base APIController for auto creating CRUD APIs, configurable via Meta class
10+
Base APIController for auto creating CRUD APIs, configurable via APIMeta class
1111
APIs auto generated:
1212
Creat
1313
PUT /{id} - Create a single Object
@@ -32,7 +32,7 @@ class CrudAPIController(metaclass=CrudApiMetaclass):
3232
sensitive_fields: fields to be ignored
3333
3434
Example:
35-
class Meta
35+
class APIMeta
3636
model = Event
3737
generate_crud = False
3838
model_exclude = ["field1", "field2"]

easy/controller/meta.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, service=None): # type: ignore
2727
# Critical to set __Meta
2828
self.service = service
2929

30-
_model_opts: ModelOptions = ModelOptions.get_model_options(self.Meta)
30+
_model_opts: ModelOptions = ModelOptions.get_model_options(self.APIMeta)
3131
if self.model and _model_opts:
3232
ModelOptions.set_model_meta(self.model, _model_opts)
3333

@@ -36,10 +36,10 @@ def __init__(self, service=None): # type: ignore
3636
super().__init__(model=self.model)
3737

3838

39-
class CrudApiMetaclass(ABCMeta):
39+
class CrudAPIMetaclass(ABCMeta):
4040
def __new__(mcs, name: str, bases: Tuple[Type[Any], ...], attrs: dict) -> Any:
41-
# Get configs from Meta
42-
attrs_meta = attrs.get("Meta", None)
41+
# Get configs from APIMeta
42+
attrs_meta = attrs.get("APIMeta", None)
4343
model_opts: ModelOptions = ModelOptions.get_model_options(attrs_meta)
4444

4545
# Get all attrs from parents excluding private ones

easy/domain/meta.py

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

44

55
class CrudModel(object):
6-
Meta: Dict = {}
6+
APIMeta: Dict = {}
77

88
def __init__(self, model: Any):
99
self.model = model

tests/easy_app/controllers.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AutoGenCrudAPIController(CrudAPIController):
2828
def __init__(self, service: EventService):
2929
super().__init__(service)
3030

31-
class Meta:
31+
class APIMeta:
3232
model = Event
3333
model_join = True
3434

@@ -42,7 +42,7 @@ class RecursiveAPIController(CrudAPIController):
4242
def __init__(self, service: EventService):
4343
super().__init__(service)
4444

45-
class Meta:
45+
class APIMeta:
4646
model = Event
4747
model_fields = "__all__"
4848
model_join = True
@@ -58,7 +58,7 @@ class InheritedRecursiveAPIController(AutoGenCrudAPIController):
5858
def __init__(self, service: EventService):
5959
super().__init__(service)
6060

61-
class Meta:
61+
class APIMeta:
6262
model = Event
6363
model_fields = "__all__"
6464
model_join = True
@@ -74,7 +74,7 @@ class AutoGenCrudNoJoinAPIController(CrudAPIController):
7474
def __init__(self, service: EventService):
7575
super().__init__(service)
7676

77-
class Meta:
77+
class APIMeta:
7878
model = Event
7979
model_fields = "__all__"
8080
model_join = False
@@ -88,7 +88,7 @@ class AutoGenCrudSomeFieldsAPIController(CrudAPIController):
8888
For unit testings of the no-m2m-fields model
8989
"""
9090

91-
class Meta:
91+
class APIMeta:
9292
model = Client
9393
model_fields = [
9494
"key",
@@ -105,7 +105,7 @@ class EasyCrudAPIController(CrudAPIController):
105105
def __init__(self, service: EventService):
106106
super().__init__(service)
107107

108-
class Meta:
108+
class APIMeta:
109109
model = Event
110110
model_exclude = [
111111
"category",
@@ -149,7 +149,7 @@ def __init__(self, service: EventService):
149149
super().__init__(service)
150150
self.service = service
151151

152-
class Meta:
152+
class APIMeta:
153153
model = Event
154154

155155
@http_get("/must_be_authenticated/", permissions=[IsAuthenticated])
@@ -189,7 +189,7 @@ def __init__(self, service: EventService):
189189
super().__init__(service)
190190
self.service = service
191191

192-
class Meta:
192+
class APIMeta:
193193
model = Event
194194

195195

@@ -203,7 +203,7 @@ def __init__(self, service: EventService):
203203
super().__init__(service)
204204
self.service = service
205205

206-
class Meta:
206+
class APIMeta:
207207
model = Event
208208
generate_crud = False
209209

@@ -218,7 +218,7 @@ def __init__(self, service: EventService):
218218
super().__init__(service)
219219
self.service = service
220220

221-
class Meta:
221+
class APIMeta:
222222
model = Event
223223
generate_crud = False
224224
model_exclude = [

tests/easy_app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Category(TestBaseModel):
1010
title = models.CharField(max_length=100)
1111
status = models.PositiveSmallIntegerField(default=1, null=True)
1212

13-
class ApiMeta:
13+
class APIMeta:
1414
generate_crud = False
1515

1616

0 commit comments

Comments
 (0)