Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def db_value(self, model):
# if no model is provided then return None
if model is None:
return None
# check reference model and passing model is same
if not issubclass(model.__class__, self.model_ref):
raise errors.ReferenceTypeError(f'Invalid reference type. Field "{self.name}" required value type '
f'"{self.model_ref.__name__}", but got "{model.__class__.__name__}"')
# Get document reference from firestore
return firestore.DocumentReference(*utils.ref_path(model.key), client=db.conn)
def db_value(self, model):
# check reference model and passing model is same
if not issubclass(model.__class__, self.model_ref):
raise errors.ReferenceTypeError(f'Invalid reference type. Field "{self.name}" required value type '
f'{self.model_ref.__name__}, but got {model.__class__.__name__}')
# Get document reference from firestore
return firestore.DocumentReference(*utils.ref_path(model.key), client=db.conn)
def __init__(self, model_ref, *args, **kwargs):
super().__init__(*args, **kwargs)
# Check model ref class is subclass for Model
from fireo.models import Model
if not issubclass(model_ref, Model):
raise errors.ReferenceTypeError(f'Reference model "{model_ref.__name__}" must be inherit from Model class')
self.model_ref = model_ref
self.auto_load = True
self.on_load = None
def __init__(self, model_ref, *args, **kwargs):
super().__init__(*args, **kwargs)
# Check model ref class is subclass for Model
from fireo.models import Model
if not issubclass(model_ref, Model):
raise errors.ReferenceTypeError(f'Reference model {model_ref.__name__} must be inherit from Model class')
self.model_ref = model_ref
self.auto_load = True
self.on_load = None