def update_push_tokens(self, push_tokens_data, api_version): if 'apns' in push_tokens_data: apns_token = push_tokens_data.get('apns') # Delete user devices self.delete_apns_devices() if apns_token is not None: # Delete devices with same apns_token APNSDevice.objects.filter(registration_id=apns_token).delete() # Create new device for user with apns_token apns_device = APNSDevice(registration_id=apns_token, user=self) apns_device.api_version = api_version apns_device.save() if 'gcm' in push_tokens_data: gcm_token = push_tokens_data.get('gcm') # Delete user devices self.delete_gcm_devices() if gcm_token is not None: # Delete devices with same gcm_token GCMDevice.objects.filter(registration_id=gcm_token).delete() # Create new gcm device for user with gcm_token gcm_device = GCMDevice(registration_id=gcm_token, user=self) gcm_device.api_version = api_version gcm_device.save()