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