modelcluster/models.py
def from_serializable_data(cls, data, check_fks=True, strict_fks=False):
        """
        Build an instance of this model from the JSON-like structure passed in,
        recursing into related objects as required.
        If check_fks is true, it will check whether referenced foreign keys still
        exist in the database.
        - dangling foreign keys on related objects are dealt with by either nullifying the key or
        dropping the related object, according to the 'on_delete' setting.
        - dangling foreign keys on the base object will be nullified, unless strict_fks is true,
        in which case any dangling foreign keys with on_delete=CASCADE will cause None to be
        returned for the entire object.
        """
        obj = model_from_serializable_data(cls, data, check_fks=check_fks, strict_fks=strict_fks)
        if obj is None:
            return None

        child_relations = get_all_child_relations(cls)

        for rel in child_relations:
            rel_name = rel.get_accessor_name()
            try:
                child_data_list = data[rel_name]
            except KeyError:
                continue

            related_model = rel.related_model
            if hasattr(related_model, 'from_serializable_data'):
                children = [
                    related_model.from_serializable_data(child_data, check_fks=check_fks, strict_fks=True)
                    for child_data in child_data_list
                ]
            else:
                children = [
                    model_from_serializable_data(related_model, child_data, check_fks=check_fks, strict_fks=True)
                    for child_data in child_data_list
                ]

            children = filter(lambda child: child is not None, children)

            setattr(obj, rel_name, children)

        return obj
def from_serializable_data(cls, data, check_fks=True, strict_fks=False):
        obj = model_from_serializable_data(cls, data, check_fks=check_fks, strict_fks=strict_fks)
        if obj is None:
            return None

        child_relations = get_all_child_relations(cls)

        for rel in child_relations:
            rel_name = rel.get_accessor_name()
            try:
                child_data_list = data[rel_name]
            except KeyError:
                continue

            related_model = rel.related_model
            if hasattr(related_model, 'from_serializable_data'):
                children = [
                    related_model.from_serializable_data(child_data, check_fks=check_fks, strict_fks=True)
                    for child_data in child_data_list
                ]
            else:
                children = [
                    model_from_serializable_data(related_model, child_data, check_fks=check_fks, strict_fks=True)
                    for child_data in child_data_list
                ]

            children = filter(lambda child: child is not None, children)

            setattr(obj, rel_name, children)

        return obj
def from_serializable_data ( cls , data , check_fks = True , strict_fks = False ) : obj = model_from_serializable_data ( cls , data , check_fks = check_fks , strict_fks = strict_fks ) if obj is None : return None child_relations = get_all_child_relations ( cls ) for rel in child_relations : rel_name = rel . get_accessor_name ( ) try : child_data_list = data [ rel_name ] except KeyError : continue related_model = rel . related_model if hasattr ( related_model , 'from_serializable_data' ) : children = [ related_model . from_serializable_data ( child_data , check_fks = check_fks , strict_fks = True ) for child_data in child_data_list ] else : children = [ model_from_serializable_data ( related_model , child_data , check_fks = check_fks , strict_fks = True ) for child_data in child_data_list ] children = filter ( lambda child : child is not None , children ) setattr ( obj , rel_name , children ) return obj
Build an instance of this model from the JSON-like structure passed in,
        recursing into related objects as required.
        If check_fks is true, it will check whether referenced foreign keys still
        exist in the database.
        - dangling foreign keys on related objects are dealt with by either nullifying the key or
        dropping the related object, according to the 'on_delete' setting.
        - dangling foreign keys on the base object will be nullified, unless strict_fks is true,
        in which case any dangling foreign keys with on_delete=CASCADE will cause None to be
        returned for the entire object.
Build an instance of this model from the JSON - like structure passed in recursing into related objects as required . If check_fks is true it will check whether referenced foreign keys still exist in the database . - dangling foreign keys on related objects are dealt with by either nullifying the key or dropping the related object according to the on_delete setting . - dangling foreign keys on the base object will be nullified unless strict_fks is true in which case any dangling foreign keys with on_delete = CASCADE will cause None to be returned for the entire object .