当前位置: 首页>>代码示例>>Python>>正文


Python loading.get_model方法代码示例

本文整理汇总了Python中django.db.models.loading.get_model方法的典型用法代码示例。如果您正苦于以下问题:Python loading.get_model方法的具体用法?Python loading.get_model怎么用?Python loading.get_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.loading的用法示例。


在下文中一共展示了loading.get_model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_usersettings_model

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def get_usersettings_model():
    """
    Returns the ``UserSettings`` model that is active in this project.
    """
    try:
        from django.apps import apps
        get_model = apps.get_model
    except ImportError:
        from django.db.models.loading import get_model

    try:
        app_label, model_name = settings.USERSETTINGS_MODEL.split('.')
    except ValueError:
        raise ImproperlyConfigured('USERSETTINGS_MODEL must be of the '
                                   'form "app_label.model_name"')
    usersettings_model = get_model(app_label, model_name)
    if usersettings_model is None:
        raise ImproperlyConfigured('USERSETTINGS_MODEL refers to model "%s" that has '
                                   'not been installed' % settings.USERSETTINGS_MODEL)
    return usersettings_model 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:22,代码来源:shortcuts.py

示例2: get_model

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def get_model(model):
    """
    Given a model name as ``app_label.ModelName``, returns the Django model.
    """
    try:
        if isinstance(model, str):
            app_label, model_name = model.split('.', 1)
            m = loading.get_model(app_label, model_name)
            if not m:  # pragma: no cover
                raise LookupError()  # Django < 1.7 just returns None
            return m
        elif issubclass(model, models.Model):
            return model
    except (LookupError, ValueError):
        pass
    raise ValueError(model) 
开发者ID:dfunckt,项目名称:django-connections,代码行数:18,代码来源:models.py

示例3: define_relationship

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def define_relationship(name, from_model, to_model):
    if name in _relationship_registry:
        raise KeyError(name)
    
    _from_ctype = from_model
    _to_ctype = to_model
    
    if isinstance(_from_ctype, str):
        _from_ctype = get_model(_from_ctype)
    if isinstance(_to_ctype, str):
        _to_ctype = get_model(_to_ctype)
    
    if not isinstance(_from_ctype, ContentType):
        _from_ctype = ContentType.objects.get_for_model(_from_ctype)
    if not isinstance(_to_ctype, ContentType):
        _to_ctype = ContentType.objects.get_for_model(_to_ctype)
    
    relationship = Relationship(name=name,
                                from_content_type=_from_ctype,
                                to_content_type=_to_ctype)
    
    _relationship_registry[name] = relationship
    return relationship 
开发者ID:dfunckt,项目名称:django-connections,代码行数:25,代码来源:models.py

示例4: render

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def render(self, name, value, attrs=None, renderer=None, choices=()):
        if value is None:
            value = []

        if not isinstance(value, (list, tuple)):
            # This is a ForeignKey field. We must allow only one item.
            value = [value]

        values = get_model(self.model).objects.filter(pk__in=value)
        try:
            final_attrs = self.build_attrs(attrs, name=name)
        except TypeError as e:
            # Fallback for django 1.10+
            final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})

        return render_to_string('searchableselect/select.html', dict(
            field_id=final_attrs['id'],
            field_name=final_attrs['name'],
            values=values,
            model=self.model,
            search_field=self.search_field,
            limit=self.limit,
            many=self.many
        )) 
开发者ID:and3rson,项目名称:django-searchable-select,代码行数:26,代码来源:widgets.py

示例5: filter_models

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def filter_models(request):
    model_name = request.GET.get('model')
    search_field = request.GET.get('search_field')
    value = request.GET.get('q')
    limit = int(request.GET.get('limit', 10))
    try:
        model = get_model(model_name)
    except LookupError as e:  # pragma: no cover
        return JsonResponse(dict(status=400, error=e.message))
    except (ValueError, AttributeError) as e:  # pragma: no cover
        return JsonResponse(dict(status=400, error='Malformed model parameter.'))

    values = model.objects.filter(**{'{}__icontains'.format(search_field): value})[:limit]
    values = [
        dict(pk=v.pk, name=smart_str(v))
        for v
        in values
    ]

    return JsonResponse(dict(result=values)) 
开发者ID:and3rson,项目名称:django-searchable-select,代码行数:22,代码来源:views.py

示例6: bsdfs_csv

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def bsdfs_csv(v, bsdfs):
    """ Return a list of BSDFs formatted as a tab-separated-value file """
    if v not in BSDF_VERSIONS:
        raise Http404

    response = HttpResponse(mimetype='text/csv')
    #response['Content-Disposition'] = 'attachment; filename="bsdfs.csv"'
    writer = csv.writer(response)

    bsdf_model = get_model('bsdfs', 'ShapeBsdfLabel_' + v)
    fields = [f.name for f in bsdf_model._meta.fields]
    writer.writerow(fields)

    for bsdf in bsdfs:
        row = []
        for name in fields:
            value = getattr(bsdf, name)
            if hasattr(value, 'isoformat'):
                row.append(value.isoformat())
            else:
                row.append(value)
        writer.writerow(row)

    return response 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:26,代码来源:views.py

示例7: bsdf_all

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def bsdf_all(request, v, template='endless_list.html', extra_context=None):
    if v not in BSDF_VERSIONS:
        raise Http404

    entries = get_model('bsdfs', 'ShapeBsdfLabel_' + v).objects.all() \
        .filter(time_ms__isnull=False,
                shape__photo__synthetic=False,
                shape__photo__inappropriate=False) \
        .order_by('-id')

    context = dict_union({
        'nav': 'browse/bsdf-%s' % v, 'subnav': 'all',
        'entries': entries,
        'base_template': 'bsdf_base.html',
        'thumb_template': 'bsdf_%s_shape_thumb.html' % v,
        'header': 'All submissions',
        'header_small': 'sorted by date',
        'v': v,
        #'enable_voting': False,
    }, extra_context)

    return render(request, template, context) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:24,代码来源:views.py

示例8: bsdf_wd_voted_none

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def bsdf_wd_voted_none(request, template='endless_list.html',
                       extra_context=None):

    v = 'wd'
    bsdf_model = get_model('bsdfs', 'ShapeBsdfLabel_' + v)
    entries = bsdf_model.objects \
        .filter(give_up=False, admin_score=0, time_ms__gt=500) \
        .order_by('-shape__synthetic', '-shape__pixel_area')  # '-shape__pixel_area', '-shape__correct_score')

    context = dict_union({
        'nav': 'browse/bsdf-%s' % v,
        'subnav': 'vote',
        'entries': entries,
        'base_template': 'bsdf_base.html',
        'thumb_template': 'bsdf_wd_thumb_vote.html',
        'v': v,
        'enable_voting': True,
    }, extra_context)

    return render(request, template, context) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:22,代码来源:views.py

示例9: bsdf_wd_voted_yes

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def bsdf_wd_voted_yes(request, template='endless_list.html',
                      extra_context=None):

    v = 'wd'
    bsdf_model = get_model('bsdfs', 'ShapeBsdfLabel_' + v)
    entries = bsdf_model.objects \
        .filter(admin_score__gt=0) \
        .order_by('-admin_score', '-shape__pixel_area', '-shape__correct_score')

    context = dict_union({
        'nav': 'browse/bsdf-%s' % v,
        'subnav': 'voted-yes',
        'entries': entries,
        'base_template': 'bsdf_base.html',
        'thumb_template': 'bsdf_wd_thumb_vote.html',
        'v': v,
        'enable_voting': True,
    }, extra_context)

    return render(request, template, context) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:22,代码来源:views.py

示例10: bsdf_wd_voted_no

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def bsdf_wd_voted_no(request, template='endless_list.html',
                     extra_context=None):

    v = 'wd'
    bsdf_model = get_model('bsdfs', 'ShapeBsdfLabel_' + v)
    entries = bsdf_model.objects \
        .filter(admin_score__lt=0) \
        .order_by('admin_score', '-shape__pixel_area', '-shape__correct_score')

    context = dict_union({
        'nav': 'browse/bsdf-%s' % v,
        'subnav': 'voted-no',
        'entries': entries,
        'base_template': 'bsdf_base.html',
        'thumb_template': 'bsdf_wd_thumb_vote.html',
        'v': v,
        'enable_voting': True,
    }, extra_context)

    return render(request, template, context) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:22,代码来源:views.py

示例11: get_embed_video_model

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def get_embed_video_model():
    try:
        app_label, model_name =\
            settings.WAGTAILEMBEDVIDEO_VIDEO_MODEL.split('.')
    except AttributeError:
        return EmbedVideo
    except ValueError:
        raise ImproperlyConfigured(
            "WAGTAILEMBEDVIDEO_VIDEO_MODEL must be of the form \
            'app_label.model_name'")

    embed_video_model = get_model(app_label, model_name)
    if embed_video_model is None:
        raise ImproperlyConfigured(
            "WAGTAILEMBEDVIDEO_VIDEO_MODEL refers to model '%s' that has not \
            been installed" % settings.WAGTAILEMBEDVIDEO_VIDE_MODEL)
    return embed_video_model 
开发者ID:infoportugal,项目名称:wagtail-embedvideos,代码行数:19,代码来源:models.py

示例12: _fetch_objects

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def _fetch_objects(self, references):
        objects = defaultdict(list)
        for content_type, ids in references.items():
            model = get_model(*content_type.split('.'))
            ids = set(ids)
            instances = self.fetch_model_instances(model, ids)
            objects[content_type] = instances
        return objects 
开发者ID:GetStream,项目名称:stream-django,代码行数:10,代码来源:enrich.py

示例13: _inject_objects

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def _inject_objects(self, activities, objects, fields):
        for activity, field in itertools.product(activities, fields):
            if not self.is_ref(activity, field):
                continue
            f_ct, f_id = activity[field].split(':')
            model = get_model(*f_ct.split('.'))
            f_id = model._meta.pk.to_python(f_id)

            instance = objects[f_ct].get(f_id)
            if instance is None:
                activity.track_not_enriched_field(field, activity[field])
            else:
                activity[field] = self.enrich_instance(instance) 
开发者ID:GetStream,项目名称:stream-django,代码行数:15,代码来源:enrich.py

示例14: get_tenant_model

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def get_tenant_model():
    return get_model(settings.TENANT_MODEL) 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:4,代码来源:utils.py

示例15: get_tenant_domain_model

# 需要导入模块: from django.db.models import loading [as 别名]
# 或者: from django.db.models.loading import get_model [as 别名]
def get_tenant_domain_model():
    return get_model(settings.TENANT_DOMAIN_MODEL) 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:4,代码来源:utils.py


注:本文中的django.db.models.loading.get_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。