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


Python apps.get_models方法代码示例

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


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

示例1: _check_referencing_to_swapped_model

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def _check_referencing_to_swapped_model(self):
        if (self.rel.to not in apps.get_models() and
                not isinstance(self.rel.to, six.string_types) and
                self.rel.to._meta.swapped):
            model = "%s.%s" % (
                self.rel.to._meta.app_label,
                self.rel.to._meta.object_name
            )
            return [
                checks.Error(
                    ("Field defines a relation with the model '%s', "
                     "which has been swapped out.") % model,
                    hint="Update the relation to point at 'settings.%s'." % self.rel.to._meta.swappable,
                    obj=self,
                    id='fields.E301',
                )
            ]
        return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:related.py

示例2: swappable_setting

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def swappable_setting(self):
        """
        Gets the setting that this is powered from for swapping, or None
        if it's not swapped in / marked with swappable=False.
        """
        if self.swappable:
            # Work out string form of "to"
            if isinstance(self.rel.to, six.string_types):
                to_string = self.rel.to
            else:
                to_string = "%s.%s" % (
                    self.rel.to._meta.app_label,
                    self.rel.to._meta.object_name,
                )
            # See if anything swapped/swappable matches
            for model in apps.get_models(include_swapped=True):
                if model._meta.swapped:
                    if model._meta.swapped == to_string:
                        return model._meta.swappable
                if ("%s.%s" % (model._meta.app_label, model._meta.object_name)) == to_string and model._meta.swappable:
                    return model._meta.swappable
        return None 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:related.py

示例3: _build_kml_sources

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def _build_kml_sources(self, sources):
        """
        Goes through the given sources and returns a 3-tuple of
        the application label, module name, and field name of every
        GeometryField encountered in the sources.

        If no sources are provided, then all models.
        """
        kml_sources = []
        if sources is None:
            sources = apps.get_models()
        for source in sources:
            if isinstance(source, models.base.ModelBase):
                for field in source._meta.fields:
                    if isinstance(field, GeometryField):
                        kml_sources.append((source._meta.app_label,
                                            source._meta.model_name,
                                            field.name))
            elif isinstance(source, (list, tuple)):
                if len(source) != 3:
                    raise ValueError('Must specify a 3-tuple of (app_label, module_name, field_name).')
                kml_sources.append(source)
            else:
                raise TypeError('KML Sources must be a model or a 3-tuple.')
        return kml_sources 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:kml.py

示例4: check_all_models

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def check_all_models(app_configs=None, **kwargs):
    errors = []
    for model in apps.get_models():
        if app_configs is None or model._meta.app_config in app_configs:
            if not inspect.ismethod(model.check):
                errors.append(
                    Error(
                        "The '%s.check()' class method is "
                        "currently overridden by %r." % (
                            model.__name__, model.check),
                        hint=None,
                        obj=model,
                        id='models.E020'
                    )
                )
            else:
                errors.extend(model.check(**kwargs))
    return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:model_checks.py

示例5: collect_invalidations

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def collect_invalidations(self):
        models = apps.get_models()
        data = defaultdict(list)
        cache = cachalot_caches.get_cache()
        for db_alias in settings.DATABASES:
            get_table_cache_key = cachalot_settings.CACHALOT_TABLE_KEYGEN
            model_cache_keys = {
                get_table_cache_key(db_alias, model._meta.db_table): model
                for model in models}
            for cache_key, timestamp in cache.get_many(
                    model_cache_keys.keys()).items():
                invalidation = datetime.fromtimestamp(timestamp)
                model = model_cache_keys[cache_key]
                data[db_alias].append(
                    (model._meta.app_label, model.__name__, invalidation))
                if self.last_invalidation is None \
                        or invalidation > self.last_invalidation:
                    self.last_invalidation = invalidation
            data[db_alias].sort(key=lambda row: row[2], reverse=True)
        self.record_stats({'invalidations_per_db': data.items()}) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:22,代码来源:panels.py

示例6: _build_kml_sources

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def _build_kml_sources(self, sources):
        """
        Go through the given sources and return a 3-tuple of the application
        label, module name, and field name of every GeometryField encountered
        in the sources.

        If no sources are provided, then all models.
        """
        kml_sources = []
        if sources is None:
            sources = apps.get_models()
        for source in sources:
            if isinstance(source, models.base.ModelBase):
                for field in source._meta.fields:
                    if isinstance(field, GeometryField):
                        kml_sources.append((source._meta.app_label,
                                            source._meta.model_name,
                                            field.name))
            elif isinstance(source, (list, tuple)):
                if len(source) != 3:
                    raise ValueError('Must specify a 3-tuple of (app_label, module_name, field_name).')
                kml_sources.append(source)
            else:
                raise TypeError('KML Sources must be a model or a 3-tuple.')
        return kml_sources 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:kml.py

示例7: priority_connect

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def priority_connect(self, receiver, sender=None, children=True):
    if sender and children:
        if sender._meta.abstract:
            for child in apps.get_models():
                if issubclass(child, sender):
                    priority_connect(self, receiver, child, children=False)
            return

    lookup_key = (_make_id(receiver), _make_id(sender))

    with self.lock:
        self._clear_dead_receivers()
        for r_key, _ in self.receivers:
            if r_key == lookup_key:
                break
        else:
            # Adding priority receiver to beginning of the list
            self.receivers.insert(0, (lookup_key, receiver))
        self.sender_receivers_cache.clear() 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:21,代码来源:signals.py

示例8: test_dynamic_load

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def test_dynamic_load(self):
        """
        Makes a new model at runtime and ensures it goes into the right place.
        """
        old_models = list(apps.get_app_config("apps").get_models())
        # Construct a new model in a new app registry
        body = {}
        new_apps = Apps(["apps"])
        meta_contents = {
            'app_label': "apps",
            'apps': new_apps,
        }
        meta = type("Meta", (), meta_contents)
        body['Meta'] = meta
        body['__module__'] = TotallyNormal.__module__
        temp_model = type("SouthPonies", (models.Model,), body)
        # Make sure it appeared in the right place!
        self.assertEqual(list(apps.get_app_config("apps").get_models()), old_models)
        with self.assertRaises(LookupError):
            apps.get_model("apps", "SouthPonies")
        self.assertEqual(new_apps.get_model("apps", "SouthPonies"), temp_model) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:tests.py

示例9: get_file_fields

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def get_file_fields():
    """
        Get all fields which are inherited from FileField
    """

    # get models

    all_models = apps.get_models()

    # get fields

    fields = []

    for model in all_models:
        for field in model._meta.get_fields():
            if isinstance(field, models.FileField):
                fields.append(field)

    return fields 
开发者ID:akolpakov,项目名称:django-unused-media,代码行数:21,代码来源:utils.py

示例10: _check_relation_model_exists

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def _check_relation_model_exists(self):
        rel_is_missing = self.rel.to not in apps.get_models()
        rel_is_string = isinstance(self.rel.to, six.string_types)
        model_name = self.rel.to if rel_is_string else self.rel.to._meta.object_name
        if rel_is_missing and (rel_is_string or not self.rel.to._meta.swapped):
            return [
                checks.Error(
                    ("Field defines a relation with model '%s', which "
                     "is either not installed, or is abstract.") % model_name,
                    hint=None,
                    obj=self,
                    id='fields.E300',
                )
            ]
        return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:related.py

示例11: check_generic_foreign_keys

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def check_generic_foreign_keys(**kwargs):
    from .fields import GenericForeignKey

    errors = []
    fields = (obj
        for cls in apps.get_models()
        for obj in six.itervalues(vars(cls))
        if isinstance(obj, GenericForeignKey))
    for field in fields:
        errors.extend(field.check())
    return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:checks.py

示例12: handle

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def handle(self, *args, **options):
        # We need to execute the post migration callback manually in order
        # to append the view permission on the proxy model. Then the following
        # script will create the appropriate content type and move the
        # permissions under this. If we don't call the callback the script
        # will create only the basic permissions (add, change, delete)
        update_permissions(
            apps.get_app_config('admin_view_permission'),
            apps.get_app_config('admin_view_permission'),
            verbosity=1,
            interactive=True,
            using='default',
        )

        for model in apps.get_models():
            opts = model._meta
            ctype, created = ContentType.objects.get_or_create(
                app_label=opts.app_label,
                model=opts.object_name.lower(),
            )

            for codename, name in get_all_permissions(opts, ctype):
                perm, created = Permission.objects.get_or_create(
                    codename=codename,
                    content_type=ctype,
                    defaults={'name': name},
                )
                if created:
                    self.delete_parent_perms(perm)
                    self.stdout.write('Adding permission {}\n'.format(perm)) 
开发者ID:ctxis,项目名称:django-admin-view-permission,代码行数:32,代码来源:fix_proxy_permissions.py

示例13: __init__

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def __init__(self):
        models = apps.get_models()
        self.model_classes = dict(map(lambda x: (x._meta.db_table, x), models))
        self.models = dict(map(lambda x: (self.model_key(x), self.serialize_model(x)), models))

        for model in models:
            for related_model in self.get_related_models(model):
                if self.model_key(related_model) in self.models:
                    continue
                self.models[self.model_key(related_model)] = self.serialize_model(related_model)

        self.media_storage = get_storage_class(settings.JET_MEDIA_FILE_STORAGE)() 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:14,代码来源:configuration.py

示例14: get_descendant_models

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def get_descendant_models(cls):
        return [model for model in apps.get_models()
                if issubclass(model, AbstractBaseRule)] 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:5,代码来源:rules.py

示例15: generate_view_permissions

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_models [as 别名]
def generate_view_permissions():
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth.models import Permission
    from django.apps import apps

    for model in apps.get_models():
        Permission.objects.get_or_create(
            codename='view_{}'.format(model._meta.model_name),
            name='Can view {}'.format(model._meta.verbose_name),
            content_type=ContentType.objects.get_for_model(model),
        ) 
开发者ID:pengutronix,项目名称:aiohttp-json-rpc,代码行数:13,代码来源:__init__.py


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