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


Python models.get_model方法代码示例

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


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

示例1: update_v3

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def update_v3(self, vlan, user):
        """Update vlan."""

        try:
            env_model = get_model('ambiente', 'Ambiente')
            ogp_models = get_app('api_ogp', 'models')

            env = env_model.get_by_pk(vlan.get('environment'))

            self.ambiente = env
            self.nome = vlan.get('name')
            self.num_vlan = vlan.get('num_vlan')
            self.descricao = vlan.get('description')
            self.acl_file_name = vlan.get('acl_file_name')
            self.acl_valida = vlan.get('acl_valida', False)
            self.acl_file_name_v6 = vlan.get('acl_file_name_v6')
            self.acl_valida_v6 = vlan.get('acl_valida_v6', False)
            self.ativada = vlan.get('active', False)
            self.vrf = vlan.get('vrf')
            self.acl_draft = vlan.get('acl_draft')
            self.acl_draft_v6 = vlan.get('acl_draft_v6')

            old_vlan = self.get_by_pk(self.id)
        except Exception, e:
            raise VlanErrorV3(e) 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:27,代码来源:models.py

示例2: _is_ipv6_in_use

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def _is_ipv6_in_use(self, ipv6, id_vip=None):
        id_vip = id_vip if id_vip else self.id
        spm_model = get_model('requisicaovips', 'ServerPoolMember')
        vp_model = get_model('api_vip_request', 'VipRequest')

        is_in_use = True

        pm_count = spm_model.objects.filter(ipv6=ipv6).exclude(
            server_pool__vipporttopool__requisicao_vip__ipv6=self.id
        ).count()

        vip_count = vp_model.objects.filter(
            ipv6=ipv6
        ).exclude(pk=id_vip).count()

        if vip_count == 0 and pm_count == 0:
            is_in_use = False

        return is_in_use 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:21,代码来源:models.py

示例3: _get_model_from_node

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def _get_model_from_node(self, node, attr):
        """
        Helper to look up a model from a <object model=...> or a <field
        rel=... to=...> node.
        """
        model_identifier = node.getAttribute(attr)
        if not model_identifier:
            raise base.DeserializationError(
                "<%s> node is missing the required '%s' attribute" \
                    % (node.nodeName, attr))
        try:
            Model = models.get_model(*model_identifier.split("."))
        except TypeError:
            Model = None
        if Model is None:
            raise base.DeserializationError(
                "<%s> node has invalid model identifier: '%s'" % \
                    (node.nodeName, model_identifier))
        return Model 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:xml_serializer.py

示例4: context

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def context(self, context):
        btns = []
        for b in self.q_btns:
            btn = {}
            if 'model' in b:
                model = self.get_model(b['model'])
                if not self.user.has_perm("%s.view_%s" % (model._meta.app_label, model._meta.model_name)):
                    continue
                btn['url'] = reverse("%s:%s_%s_%s" % (self.admin_site.app_name, model._meta.app_label,
                                                      model._meta.model_name, b.get('view', 'changelist')))
                btn['title'] = model._meta.verbose_name
                btn['icon'] = self.dashboard.get_model_icon(model)
            else:
                try:
                    btn['url'] = reverse(b['url'])
                except NoReverseMatch:
                    btn['url'] = b['url']

            if 'title' in b:
                btn['title'] = b['title']
            if 'icon' in b:
                btn['icon'] = b['icon']
            btns.append(btn)

        context.update({'btns': btns}) 
开发者ID:madre,项目名称:devops,代码行数:27,代码来源:dashboard.py

示例5: _test_run_sql

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def _test_run_sql(self, app_label, should_run, hints=None):
        with override_settings(DATABASE_ROUTERS=[MigrateEverythingRouter()]):
            project_state = self.set_up_test_model(app_label)

        sql = """
        INSERT INTO {0}_pony (pink, weight) VALUES (1, 3.55);
        INSERT INTO {0}_pony (pink, weight) VALUES (3, 5.0);
        """.format(app_label)

        operation = migrations.RunSQL(sql, hints=hints or {})
        # Test the state alteration does nothing
        new_state = project_state.clone()
        operation.state_forwards(app_label, new_state)
        self.assertEqual(new_state, project_state)
        # Test the database alteration
        self.assertEqual(project_state.apps.get_model(app_label, "Pony").objects.count(), 0)
        with connection.schema_editor() as editor:
            operation.database_forwards(app_label, editor, project_state, new_state)
        Pony = project_state.apps.get_model(app_label, "Pony")
        if should_run:
            self.assertEqual(Pony.objects.count(), 2)
        else:
            self.assertEqual(Pony.objects.count(), 0) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:test_multidb.py

示例6: _test_run_python

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def _test_run_python(self, app_label, should_run, hints=None):
        with override_settings(DATABASE_ROUTERS=[MigrateEverythingRouter()]):
            project_state = self.set_up_test_model(app_label)

        # Create the operation
        def inner_method(models, schema_editor):
            Pony = models.get_model(app_label, "Pony")
            Pony.objects.create(pink=1, weight=3.55)
            Pony.objects.create(weight=5)

        operation = migrations.RunPython(inner_method, hints=hints or {})
        # Test the state alteration does nothing
        new_state = project_state.clone()
        operation.state_forwards(app_label, new_state)
        self.assertEqual(new_state, project_state)
        # Test the database alteration
        self.assertEqual(project_state.apps.get_model(app_label, "Pony").objects.count(), 0)
        with connection.schema_editor() as editor:
            operation.database_forwards(app_label, editor, project_state, new_state)
        Pony = project_state.apps.get_model(app_label, "Pony")
        if should_run:
            self.assertEqual(Pony.objects.count(), 2)
        else:
            self.assertEqual(Pony.objects.count(), 0) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:26,代码来源:test_multidb.py

示例7: test_alter_field_m2m

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def test_alter_field_m2m(self):
        project_state = self.set_up_test_model("test_alflmm", second_model=True)

        project_state = self.apply_operations("test_alflmm", project_state, operations=[
            migrations.AddField("Pony", "stables", models.ManyToManyField("Stable", related_name="ponies"))
        ])
        Pony = project_state.apps.get_model("test_alflmm", "Pony")
        self.assertFalse(Pony._meta.get_field('stables').blank)

        project_state = self.apply_operations("test_alflmm", project_state, operations=[
            migrations.AlterField(
                "Pony", "stables", models.ManyToManyField(to="Stable", related_name="ponies", blank=True)
            )
        ])
        Pony = project_state.apps.get_model("test_alflmm", "Pony")
        self.assertTrue(Pony._meta.get_field('stables').blank) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:18,代码来源:test_operations.py

示例8: test_repoint_field_m2m

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def test_repoint_field_m2m(self):
        project_state = self.set_up_test_model("test_alflmm", second_model=True, third_model=True)

        project_state = self.apply_operations("test_alflmm", project_state, operations=[
            migrations.AddField("Pony", "places", models.ManyToManyField("Stable", related_name="ponies"))
        ])
        Pony = project_state.apps.get_model("test_alflmm", "Pony")

        project_state = self.apply_operations("test_alflmm", project_state, operations=[
            migrations.AlterField("Pony", "places", models.ManyToManyField(to="Van", related_name="ponies"))
        ])

        # Ensure the new field actually works
        Pony = project_state.apps.get_model("test_alflmm", "Pony")
        p = Pony.objects.create(pink=False, weight=4.55)
        p.places.create()
        self.assertEqual(p.places.count(), 1)
        p.places.all().delete() 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:test_operations.py

示例9: get_django_model

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def get_django_model(app_label, model_name):
        return models.get_model(app_label, model_name) 
开发者ID:82Flex,项目名称:DCRM,代码行数:4,代码来源:compat.py

示例10: resolve_model

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def resolve_model(class_path):
    """
    Resolves a class path to a Django model class
    :param class_path: a string model class path
    :return:
    """
    return get_model(*class_path.split('.', 1)) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:9,代码来源:utils.py

示例11: create_v4

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def create_v4(self, as_equipment):
        """Create AsnEquipment relationship."""

        equipment = get_model('equipamento', 'Equipamento')

        self.equipment = equipment().get_by_pk(
            as_equipment.get('equipment'))
        self.asn = Asn().get_by_pk(as_equipment.get('asn'))

        self.save()

        return self 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:14,代码来源:models.py

示例12: get_model

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def get_model(self, obj):
        return self.extends_serializer(obj, 'model') 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:4,代码来源:serializers.py

示例13: update_v3

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def update_v3(self, member):
        """
        Creates pool member.

        @raise ServerPoolNotFoundError
        @raise PoolError
        @raise OperationalError
        @raise IpNotFoundError
        @raise IpError
        """

        model_ip = get_model('ip', 'Ip')
        model_ipv6 = get_model('ip', 'Ipv6')
        pools_exceptions = get_app('api_pools', 'exceptions')

        # Ip
        self.ip = model_ip.get_by_pk(member['ip']['id']) \
            if member['ip'] else None
        # Ipv6
        self.ipv6 = model_ipv6.get_by_pk(member['ipv6']['id']) \
            if member['ipv6'] else None

        self.weight = member['weight']
        self.priority = member['priority']
        self.port_real = member['port_real']
        self.member_status = member['member_status']
        self.limit = member['limit']
        self.save()

        if self.server_pool.dscp:
            if self.port_real != self.server_pool.default_port:

                raise pools_exceptions.PoolError(
                    'DRSL3 Restriction: Pool Member {} cannot have different'
                    ' port of Pool {}'.format(
                        str(self), str(self.server_pool)
                    )
                ) 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:40,代码来源:models.py

示例14: create

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def create(self, ipv4_id, networkipv4_id):
        ipv4_model = get_model('ip', 'Ip')
        networkipv4_model = get_model('ip', 'NetworkIPv4')

        ipv4 = ipv4_model.get_by_pk(ipv4_id)
        networkipv4 = networkipv4_model.get_by_pk(networkipv4_id)

        if len(DHCPRelayIPv4.objects.filter(ipv4=ipv4, networkipv4=networkipv4)) > 0:
            raise exceptions.DHCPRelayAlreadyExistsError(
                ipv4_id, networkipv4_id)

        self.ipv4 = ipv4
        self.networkipv4 = networkipv4 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:15,代码来源:models.py

示例15: validate_v3

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import get_model [as 别名]
def validate_v3(self):
        """Validate networkIPv4."""
        models = get_model("ambiente", "EnvCIDR")
        if not self.network_type:
            raise NetworkIPv4ErrorV3('Network type can not null')

        # validate if network if allow in environment
        env_id = self.vlan.ambiente.id
        configs = models().get(env_id=env_id)
        self.vlan.allow_networks_environment(configs, [self], []) 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:12,代码来源:models.py


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