@@ -71,6 +71,11 @@ def __dir__(self):
7171 def __repr__ (self ):
7272 return '{}({})' .format (self .__class__ .__name__ , pprint .pformat (self .json ))
7373
74+ @property
75+ def _resource_name (self ):
76+ from atomx .utils import model_name_to_rest
77+ return model_name_to_rest (self .__class__ .__name__ )
78+
7479 @property
7580 def _dirty_json (self ):
7681 return {k : self ._attributes [k ] for k in self ._dirty }
@@ -91,7 +96,7 @@ def create(self, session=None):
9196 session = session or self .session
9297 if not session :
9398 raise NoSessionError
94- res = session .post (self .__class__ . __name__ , json = self .json )
99+ res = session .post (self ._resource_name , json = self .json )
95100 self .__init__ (session = session , ** res )
96101 return self
97102
@@ -110,7 +115,7 @@ def save(self, session=None):
110115 session = session or self .session
111116 if not session :
112117 raise NoSessionError
113- res = session .put (self .__class__ . __name__ , self .id , json = self ._dirty_json )
118+ res = session .put (self ._resource_name , self .id , json = self ._dirty_json )
114119 self .__init__ (session = session , ** res )
115120 return self
116121
@@ -138,7 +143,7 @@ def reload(self, session=None):
138143 if not hasattr (self , 'id' ):
139144 raise ModelNotFoundError ("Can't reload without 'id' parameter. "
140145 "Forgot to save() first?" )
141- res = session .get (self .__class__ . __name__ + '/' + str (self .id ))
146+ res = session .get (self ._resource_name + '/' + str (self .id ))
142147 self .__init__ (session = session , ** res .json )
143148 return self
144149
0 commit comments