當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。