コード例 #1
0
ファイル: django.py プロジェクト: 42cc/factory_boy
def get_model(app, model):
    """Wrapper around django's get_model."""
    if 'get_model' not in _LAZY_LOADS:
        _lazy_load_get_model()

    _get_model = _LAZY_LOADS['get_model']
    return _get_model(app, model)
コード例 #2
0
ファイル: django.py プロジェクト: zyskowsk/factory_boy
def get_model(app, model):
    """Wrapper around django's get_model."""
    if 'get_model' not in _LAZY_LOADS:
        _lazy_load_get_model()

    _get_model = _LAZY_LOADS['get_model']
    return _get_model(app, model)
コード例 #3
0
ファイル: utils.py プロジェクト: fordream/Kawaz3rd
def get_model(model):
    """
    Get a model class from 'app_label.model_name' type of string
    """
    if isinstance(model, str):
        app_label, model_name = model.rsplit(".", 1)
        try:
            model = _get_model(app_label, model_name)
        except (LookupError, AppRegistryNotReady):
            return None
    return model
コード例 #4
0
def get_model(model):
    """
    Get a model class from 'app_label.model_name' type of string
    """
    if isinstance(model, str):
        app_label, model_name = model.rsplit('.', 1)
        try:
            model = _get_model(app_label, model_name)
        except (LookupError, AppRegistryNotReady):
            return None
    return model
コード例 #5
0
ファイル: utils.py プロジェクト: fordream/Kawaz3rd
def resolve_relation_lazy(relation, operation, **kwargs):
    """
    Resolve relation and call the operation with the specified kwargs.

    The operation will be called when the relation is ready to resolved.
    The original idea was copied from Django 1.2.2 source code thus the
    license belongs to the Django's license (BSD License)

    Args:
        relation (str or class): A relation which you want to resolve
        operation (fn): A callback function which will called with resolved
            relation (class) and the specified kwargs.
    """
    app_label, model_name = get_relation(relation)
    try:
        model = _get_model(app_label, model_name)
        operation(model, **kwargs)
    except AppRegistryNotReady:
        key = (app_label, model_name)
        value = (operation, kwargs)
        _pending_lookups.setdefault(key, []).append(value)
コード例 #6
0
def resolve_relation_lazy(relation, operation, **kwargs):
    """
    Resolve relation and call the operation with the specified kwargs.

    The operation will be called when the relation is ready to resolved.
    The original idea was copied from Django 1.2.2 source code thus the
    license belongs to the Django's license (BSD License)

    Args:
        relation (str or class): A relation which you want to resolve
        operation (fn): A callback function which will called with resolved
            relation (class) and the specified kwargs.
    """
    app_label, model_name = get_relation(relation)
    try:
        model = _get_model(app_label, model_name)
        operation(model, **kwargs)
    except AppRegistryNotReady:
        key = (app_label, model_name)
        value = (operation, kwargs)
        _pending_lookups.setdefault(key, []).append(value)
コード例 #7
0
ファイル: conf.py プロジェクト: radiosilence/django-items
def get_model(model):
    return _get_model(*settings.ITEMS_MODELS.get(model).split('.'))