File tree Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Original file line number Diff line number Diff line change 12
12
13
13
14
14
class DjangoOrmModel (CrudModel ):
15
- def __init__ (self , model : Type [models .Model ]) :
15
+ def __init__ (self , model : Optional [ Type [models .Model ]] = None ) -> None :
16
16
self .model = model
17
- config = ModelMetaConfig ()
18
- exclude_list = config .get_final_excluded_list (self .model ())
19
- self .m2m_fields_list : List = list (
20
- _field
21
- for _field in self .model ._meta .get_fields (include_hidden = True )
22
- if (
23
- isinstance (_field , models .ManyToManyField )
24
- and ((_field not in exclude_list ) if exclude_list else True )
17
+ if self .model :
18
+ config = ModelMetaConfig ()
19
+ exclude_list = config .get_final_excluded_list (self .model ())
20
+ self .m2m_fields_list : List = list (
21
+ _field
22
+ for _field in self .model ._meta .get_fields (include_hidden = True )
23
+ if (
24
+ isinstance (_field , models .ManyToManyField )
25
+ and ((_field not in exclude_list ) if exclude_list else True )
26
+ )
25
27
)
26
- )
27
- super ().__init__ (self .model )
28
+ super ().__init__ (self .model )
28
29
29
30
def _separate_payload (self , payload : Dict ) -> Tuple [Dict , Dict ]:
30
31
m2m_fields = {}
Original file line number Diff line number Diff line change 1
1
import logging
2
- from typing import Type
2
+ from typing import Optional , Type
3
3
4
4
from django .db import models
5
5
10
10
11
11
12
12
class BaseService (CrudService , PermissionService ):
13
- def __init__ (
14
- self ,
15
- model : Type [models .Model ],
16
- ):
13
+ def __init__ (self , model : Optional [Type [models .Model ]] = None ):
17
14
self .model = model
18
15
super ().__init__ (model = self .model )
Original file line number Diff line number Diff line change 1
1
import logging
2
- from typing import Any , Type
2
+ from typing import Any , Optional , Type
3
3
4
4
from asgiref .sync import sync_to_async
5
5
from django .db import models
10
10
11
11
12
12
class CrudService (DjangoOrmModel ):
13
- def __init__ (self , model : Type [models .Model ]):
13
+ def __init__ (self , model : Optional [ Type [models .Model ]] = None ):
14
14
super ().__init__ (model )
15
15
self .model = model
16
16
You can’t perform that action at this time.
0 commit comments