# Path: pyoko/lib/utils.py
# def un_camel(input, dash="_"):
#     return UN_CAMEL_RE.sub(r'%s\1' % dash, input).lower()


import pprint
from collections import defaultdict
from pyoko.lib.utils import un_camel
        from .listnode import ListNode
                                                 m2m=node._TYPE == 'ListNode',
                                                 is_set=True,
                                                 # node=node_name,
                                                 lnksrc='_prcs_lnks_frm_nodes_of_mdl__O2M')
                    source_mdl._add_linked_model(lnk['mdl'],
                                                 o2o=False,
                                                 null=lnk['null'],
                                                 field=node_name + '.' + lnk['field'],
                                                 reverse=reverse_name,
                                                 m2m=node._TYPE == 'ListNode',
                                                 is_set=True,
                                                 # node=node_name,
                                                 lnksrc='_prcs_lnks_frm_nodes_of_mdl__O2M_SRCMDL')
                    self._create_one_to_many(source_mdl,
                                             target_mdl=lnk['mdl'],
                                             listnode_name=lnk['reverse'])

    def _create_one_to_one(self, source_mdl, target_mdl, field_name):
        mdl_instance = source_mdl(one_to_one=True)
        mdl_instance.setattrs(_is_auto_created = True)
        for instance_ref in target_mdl._instance_registry:
            mdl = instance_ref()
            if mdl:  # if not yet garbage collected
                mdl.setattr(field_name, mdl_instance)
                # target_mdl._add_linked_model(source_mdl, o2o=True, field=field_name)

    def _create_one_to_many(self, source_mdl, target_mdl, listnode_name=None, verbose_name=None):
        # other side of n-to-many should be a ListNode
        # with our source model as the sole element
        if not listnode_name:

# Path: pyoko/lib/utils.py
# def un_camel(input, dash="_"):
#     return UN_CAMEL_RE.sub(r'%s\1' % dash, input).lower()


# Path: pyoko/registry.py
import pprint
from collections import defaultdict
from pyoko.lib.utils import un_camel
        from .listnode import ListNode

                                                 m2m=node._TYPE == 'ListNode',
                                                 is_set=True,
                                                 # node=node_name,
                                                 lnksrc='_prcs_lnks_frm_nodes_of_mdl__O2M')
                    source_mdl._add_linked_model(lnk['mdl'],
                                                 o2o=False,
                                                 null=lnk['null'],
                                                 field=node_name + '.' + lnk['field'],
                                                 reverse=reverse_name,
                                                 m2m=node._TYPE == 'ListNode',
                                                 is_set=True,
                                                 # node=node_name,
                                                 lnksrc='_prcs_lnks_frm_nodes_of_mdl__O2M_SRCMDL')
                    self._create_one_to_many(source_mdl,
                                             target_mdl=lnk['mdl'],
                                             listnode_name=lnk['reverse'])

    def _create_one_to_one(self, source_mdl, target_mdl, field_name):
        mdl_instance = source_mdl(one_to_one=True)
        mdl_instance.setattrs(_is_auto_created = True)
        for instance_ref in target_mdl._instance_registry:
            mdl = instance_ref()
            if mdl:  # if not yet garbage collected
                mdl.setattr(field_name, mdl_instance)
                # target_mdl._add_linked_model(source_mdl, o2o=True, field=field_name)

    def _create_one_to_many(self, source_mdl, target_mdl, listnode_name=None, verbose_name=None):
        # other side of n-to-many should be a ListNode
        # with our source model as the sole element
        if not listnode_name:

            listnode_name = '%s_set' % un_camel(source_mdl.__name__)