"""Models to associate a user to the Latch service."""# SPDX-License-Identifier: BSD-3-Clausefromdjango.dbimportmodelsfromdjango.contrib.authimportget_user_modelUserModel=get_user_model()defis_paired(user):""" Check if a user has configured the Latch service, returning ``True`` if so, ``False`` otherwise. """returnLatchUserConfig.objects.filter(user=user).exists()
[docs]classLatchUserConfig(models.Model):""" Store the necessary configuration to associate a user to the Latch service. .. attribute:: account_id A 64-long :class:`~django.db.models.CharField` that identifies the user in the Latch service. .. attribute:: user A :class:`~django.db.models.OneToOneField` that identifies the user who has configured the Latch service. """user=models.OneToOneField(UserModel,on_delete=models.CASCADE,related_name="latch_config",)account_id=models.CharField(unique=True,max_length=64,blank=False)