(self, other)
Puts two devices in a common sync group
Puts two devices in a common sync group
Puts two devices in a common sync group
def sync_with(self, other):
        """Puts two devices in a common sync group"""

        if self.user != other.user:
            raise ValueError("the devices do not belong to the user")

        if (
            self.sync_group is not None
            and other.sync_group is not None
            and self.sync_group != other.sync_group
        ):
            # merge sync_groups
            ogroup = other.sync_group
            Client.objects.filter(sync_group=ogroup).update(sync_group=self.sync_group)
            ogroup.delete()

        elif self.sync_group is None and other.sync_group is None:
            sg = SyncGroup.objects.create(user=self.user)
            other.sync_group = sg
            other.save()
            self.sync_group = sg
            self.save()

        elif self.sync_group is not None:
            other.sync_group = self.sync_group
            other.save()

        elif other.sync_group is not None:
            self.sync_group = other.sync_group
            self.save()
def sync_with ( self , other ) : if self . user != other . user : raise ValueError ( "the devices do not belong to the user" ) if ( self . sync_group is not None and other . sync_group is not None and self . sync_group != other . sync_group ) : # merge sync_groups ogroup = other . sync_group Client . objects . filter ( sync_group = ogroup ) . update ( sync_group = self . sync_group ) ogroup . delete ( ) elif self . sync_group is None and other . sync_group is None : sg = SyncGroup . objects . create ( user = self . user ) other . sync_group = sg other . save ( ) self . sync_group = sg self . save ( ) elif self . sync_group is not None : other . sync_group = self . sync_group other . save ( ) elif other . sync_group is not None : self . sync_group = other . sync_group self . save ( )