Closed flound1129 closed 9 years ago
Looks like someone already committed a better version of this. Closing.
Hi @flound1129 @milesrichardson, I'd lilke to know why that PR and #117 were closed ? Can you enlight me on what is the right way of doing add, addUnique and remove please ?
Hey @somq
I inherited this project from the original dev, and at the time of inheriting I closed stale issues.
This issue looks like it was closed because there was already code for it, but I don't see that code in the repo now...
I'll look into this. Hold tight
@somq I just manually merged #117
If you install from master on pip (as specified in the readme), you can now use the following methods:
def addToArray(self, key, objects):
payload = {
key: {
'__op': 'Add', 'objects': objects
}
}
self.__class__.PUT(self._absolute_url, **payload)
self.__dict__[key] = self.__dict__.get(key, []) + objects
def addUniqueToArray(self, key, objects):
payload = {
key: {
'__op': 'AddUnique', 'objects': objects
}
}
self.__class__.PUT(self._absolute_url, **payload)
data = self.__dict__.get(key, [])
self.__dict__[key] = data + [x for x in objects if x not in data]
def removeFromArray(self, key, objects):
payload = {
key: {
'__op': 'Remove', 'objects': objects
}
}
self.__class__.PUT(self._absolute_url, **payload)
self.__dict__[key] = [x for x in self.__dict__.get(key, []) if x not in objects]
@milesrichardson Alright, thanks a lot for your fast answer. We will pull and try the latest merge and let you know asap if all 3 methods are working as expected.
implements addUnique for array columns