def update_collections(self, collection_id, writeable): for coll in self.collections: if coll.id == self.source_collection_id: continue if coll.id not in collection_id and coll.id in writeable: self.collections.remove(coll) for coll_id in collection_id: if coll_id in writeable: coll = Collection.by_id(coll_id) if coll not in self.collections: self.collections.append(coll) db.session.add(self)