Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,25 @@ class BackendA(DSync):

## Update Remote system on Sync

To update a remote system, you need to extend your DSync object to define your own `create`, `update` or `delete` method for each model. The DSync engine will automatically look for `create_<modelname>`, `update_<modelname>` or `delete_<modelname>` depending on the status of the object.
Each method need to accept 2 dict, `keys` and `params` and should return a DSyncModel object:
- `keys` dict containing all identifier for this object
- `params` dict containing all attributes for this object
To update a remote system, you need to extend your DSyncModel class(es) to define your own `create`, `update` and/or `delete` methods for each model.
A DSyncModel instance stores a reference to its parent DSync class in case you need to use it to look up other model instances from the DSync's cache.

```python
class BackendA(DSync):
class Device(DSyncModel):
[...]

def create_device(self, keys, params):
@classmethod
def create(cls, dsync, ids, attrs):
## TODO add your own logic here to create the device on the remote system
item = self.default_create(object_type="device", keys=keys, params=params)
return item
return cls(**ids, **attrs)

def update_device(self, keys, params):
def update(self, attrs):
## TODO add your own logic here to update the device on the remote system
item = self.default_update(object_type="device", keys=keys, params=params)
return item
for attr, value in attrs.items():
setattr(self, attr, value)
return self

def delete(self):
## TODO add your own logic here to delete the device on the remote system
return self
```
Loading