當前位置: 首頁>>代碼示例>>Python>>正文


Python models.PositiveIntegerField方法代碼示例

本文整理匯總了Python中django.db.models.PositiveIntegerField方法的典型用法代碼示例。如果您正苦於以下問題:Python models.PositiveIntegerField方法的具體用法?Python models.PositiveIntegerField怎麽用?Python models.PositiveIntegerField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.models的用法示例。


在下文中一共展示了models.PositiveIntegerField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: document_field

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def document_field(field):
    """
    The default ``field_factory`` method for converting Django field instances to ``elasticsearch_dsl.Field`` instances.
    Auto-created fields (primary keys, for example) and one-to-many fields (reverse FK relationships) are skipped.
    """
    if field.auto_created or field.one_to_many:
        return None
    if field.many_to_many:
        return RawMultiString
    defaults = {
        models.DateField: dsl.Date(),
        models.DateTimeField: dsl.Date(),
        models.IntegerField: dsl.Long(),
        models.PositiveIntegerField: dsl.Long(),
        models.BooleanField: dsl.Boolean(),
        models.NullBooleanField: dsl.Boolean(),
        models.SlugField: dsl.String(index='not_analyzed'),
        models.DecimalField: dsl.Double(),
        models.FloatField: dsl.Float(),
    }
    return defaults.get(field.__class__, RawString) 
開發者ID:imsweb,項目名稱:django-seeker,代碼行數:23,代碼來源:mapping.py

示例2: test_invalid_content_type_field

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_invalid_content_type_field(self):
        class Model(models.Model):
            content_type = models.IntegerField()  # should be ForeignKey
            object_id = models.PositiveIntegerField()
            content_object = GenericForeignKey('content_type', 'object_id')

        self.assertEqual(Model.content_object.check(), [
            checks.Error(
                "'Model.content_type' is not a ForeignKey.",
                hint=(
                    "GenericForeignKeys must use a ForeignKey to "
                    "'contenttypes.ContentType' as the 'content_type' field."
                ),
                obj=Model.content_object,
                id='contenttypes.E003',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_checks.py

示例3: test_content_type_field_pointing_to_wrong_model

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_content_type_field_pointing_to_wrong_model(self):
        class Model(models.Model):
            content_type = models.ForeignKey('self', models.CASCADE)  # should point to ContentType
            object_id = models.PositiveIntegerField()
            content_object = GenericForeignKey('content_type', 'object_id')

        self.assertEqual(Model.content_object.check(), [
            checks.Error(
                "'Model.content_type' is not a ForeignKey to 'contenttypes.ContentType'.",
                hint=(
                    "GenericForeignKeys must use a ForeignKey to "
                    "'contenttypes.ContentType' as the 'content_type' field."
                ),
                obj=Model.content_object,
                id='contenttypes.E004',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_checks.py

示例4: test_missing_generic_foreign_key

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_missing_generic_foreign_key(self):
        class TaggedItem(models.Model):
            content_type = models.ForeignKey(ContentType, models.CASCADE)
            object_id = models.PositiveIntegerField()

        class Bookmark(models.Model):
            tags = GenericRelation('TaggedItem')

        self.assertEqual(Bookmark.tags.field.check(), [
            checks.Error(
                "The GenericRelation defines a relation with the model "
                "'contenttypes_tests.TaggedItem', but that model does not have a "
                "GenericForeignKey.",
                obj=Bookmark.tags.field,
                id='contenttypes.E004',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:test_checks.py

示例5: test_to_fields_not_checked_if_related_model_doesnt_exist

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_to_fields_not_checked_if_related_model_doesnt_exist(self):
        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            parent = ForeignObject(
                'invalid_models_tests.Parent',
                on_delete=models.SET_NULL,
                from_fields=('a', 'b'),
                to_fields=('a', 'b'),
            )

        field = Child._meta.get_field('parent')
        self.assertEqual(field.check(), [
            Error(
                "Field defines a relation with model 'invalid_models_tests.Parent', "
                "which is either not installed, or is abstract.",
                id='fields.E300',
                obj=field,
            ),
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:test_relative_fields.py

示例6: test_pointing_to_swapped_model

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_pointing_to_swapped_model(self):
        class Replacement(models.Model):
            pass

        class SwappedModel(models.Model):
            content_type = models.ForeignKey(ContentType, models.CASCADE)
            object_id = models.PositiveIntegerField()
            content_object = GenericForeignKey()

            class Meta:
                swappable = 'TEST_SWAPPED_MODEL'

        class Model(models.Model):
            rel = GenericRelation('SwappedModel')

        self.assertEqual(Model.rel.field.check(), [
            checks.Error(
                "Field defines a relation with the model "
                "'contenttypes_tests.SwappedModel', "
                "which has been swapped out.",
                hint="Update the relation to point at 'settings.TEST_SWAPPED_MODEL'.",
                obj=Model.rel.field,
                id='fields.E301',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:27,代碼來源:test_checks.py

示例7: test_field_name_ending_with_underscore

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_field_name_ending_with_underscore(self):
        class TaggedItem(models.Model):
            content_type = models.ForeignKey(ContentType, models.CASCADE)
            object_id = models.PositiveIntegerField()
            content_object = GenericForeignKey()

        class InvalidBookmark(models.Model):
            tags_ = GenericRelation('TaggedItem')

        self.assertEqual(InvalidBookmark.tags_.field.check(), [
            checks.Error(
                'Field names must not end with an underscore.',
                obj=InvalidBookmark.tags_.field,
                id='fields.E001',
            )
        ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_checks.py

示例8: test_check_subset_composite_foreign_object

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_check_subset_composite_foreign_object(self):
        class Parent(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            c = models.PositiveIntegerField()

            class Meta:
                unique_together = (('a', 'b'),)

        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            c = models.PositiveIntegerField()
            d = models.CharField(max_length=255)
            parent = ForeignObject(
                Parent,
                on_delete=models.SET_NULL,
                from_fields=('a', 'b', 'c'),
                to_fields=('a', 'b', 'c'),
                related_name='children',
            )

        self.assertEqual(Child._meta.get_field('parent').check(from_model=Child), []) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:25,代碼來源:tests.py

示例9: test_max_length_warning

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_max_length_warning(self):
        class Model(models.Model):
            integer = models.IntegerField(max_length=2)
            biginteger = models.BigIntegerField(max_length=2)
            smallinteger = models.SmallIntegerField(max_length=2)
            positiveinteger = models.PositiveIntegerField(max_length=2)
            positivesmallinteger = models.PositiveSmallIntegerField(max_length=2)

        for field in Model._meta.get_fields():
            if field.auto_created:
                continue
            with self.subTest(name=field.name):
                self.assertEqual(field.check(), [
                    DjangoWarning(
                        "'max_length' is ignored when used with %s." % field.__class__.__name__,
                        hint="Remove 'max_length' from field",
                        obj=field,
                        id='fields.W122',
                    )
                ]) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:test_ordinary_fields.py

示例10: __str__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def __str__(self):
        return self.name

# Create your models here.
#from django.contrib.contenttypes.models import ContentType
#from django.contrib.contenttypes import generic

# A solution for foreignkey
# class Foo(models.Model):
    #company_type = models.ForeignKey(ContentType)
    #company_id = models.PositiveIntegerField()
    #company = generic.GenericForeignKey('company_type', 'company_id')
#seller = Seller.objects.create()
#buyer = Buyer.objects.create()
#foo1 = Foo.objects.create(company = seller)
#foo2 = Foo.objects.create(company = buyer)
# foo1.company
# <Seller: Seller object>
# foo2.company
# <Buyer: Buyer object>
# https://stackoverflow.com/questions/30551057/django-what-are-the-alternatives-to-having-a-foreignkey-to-an-abstract-class
# https://lukeplant.me.uk/blog/posts/avoid-django-genericforeignkey/ 
開發者ID:jimmy201602,項目名稱:webterminal,代碼行數:24,代碼來源:models.py

示例11: test_alter_field_add_constraint_check__ok

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_alter_field_add_constraint_check__ok():
    with cmp_schema_editor() as editor:
        old_field = models.IntegerField()
        old_field.set_attributes_from_name('field')
        new_field = models.PositiveIntegerField()
        new_field.set_attributes_from_name('field')
        editor.alter_field(Model, old_field, new_field)
    assert editor.collected_sql == timeouts(
        'ALTER TABLE "tests_model" ADD CONSTRAINT "tests_model_field_0a53d95f_check" '
        'CHECK ("field" >= 0) NOT VALID;',
    ) + [
        'ALTER TABLE "tests_model" VALIDATE CONSTRAINT "tests_model_field_0a53d95f_check";',
    ]
    assert editor.django_sql == [
        'ALTER TABLE "tests_model" ADD CONSTRAINT "tests_model_field_0a53d95f_check" CHECK ("field" >= 0);',
    ] 
開發者ID:tbicr,項目名稱:django-pg-zero-downtime-migrations,代碼行數:18,代碼來源:test_schema.py

示例12: test_alter_field_add_constraint_check__with_flexible_timeout__ok

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_alter_field_add_constraint_check__with_flexible_timeout__ok():
    with cmp_schema_editor() as editor:
        old_field = models.IntegerField()
        old_field.set_attributes_from_name('field')
        new_field = models.PositiveIntegerField()
        new_field.set_attributes_from_name('field')
        editor.alter_field(Model, old_field, new_field)
    assert editor.collected_sql == timeouts(
        'ALTER TABLE "tests_model" ADD CONSTRAINT "tests_model_field_0a53d95f_check" '
        'CHECK ("field" >= 0) NOT VALID;',
    ) + flexible_statement_timeout(
        'ALTER TABLE "tests_model" VALIDATE CONSTRAINT "tests_model_field_0a53d95f_check";',
    )
    assert editor.django_sql == [
        'ALTER TABLE "tests_model" ADD CONSTRAINT "tests_model_field_0a53d95f_check" CHECK ("field" >= 0);',
    ] 
開發者ID:tbicr,項目名稱:django-pg-zero-downtime-migrations,代碼行數:18,代碼來源:test_schema.py

示例13: test_alter_field_drop_constraint_check__ok

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_alter_field_drop_constraint_check__ok(mocker):
    mocker.patch.object(connection, 'cursor')
    mocker.patch.object(connection.introspection, 'get_constraints').return_value = {
        'tests_model_field_0a53d95f_check': {
            'columns': ['field'],
            'primary_key': False,
            'unique': False,
            'foreign_key': None,
            'check': True,
            'index': False,
            'definition': None,
            'options': None,
        }
    }
    with cmp_schema_editor() as editor:
        old_field = models.PositiveIntegerField()
        old_field.set_attributes_from_name('field')
        new_field = models.IntegerField()
        new_field.set_attributes_from_name('field')
        editor.alter_field(Model, old_field, new_field)
    assert editor.collected_sql == timeouts(editor.django_sql)
    assert editor.django_sql == [
        'ALTER TABLE "tests_model" DROP CONSTRAINT "tests_model_field_0a53d95f_check";',
    ] 
開發者ID:tbicr,項目名稱:django-pg-zero-downtime-migrations,代碼行數:26,代碼來源:test_schema.py

示例14: test_object_id_field_type_class

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_object_id_field_type_class(self):
        field = instantiate_object_id_field(models.PositiveIntegerField)
        self.assertIsInstance(field, models.PositiveIntegerField) 
開發者ID:grantmcconnaughey,項目名稱:django-field-history,代碼行數:5,代碼來源:tests.py

示例15: test_should_positive_integer_convert_int

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import PositiveIntegerField [as 別名]
def test_should_positive_integer_convert_int():
    assert_conversion(models.PositiveIntegerField, graphene.Int) 
開發者ID:graphql-python,項目名稱:graphene-django,代碼行數:4,代碼來源:test_converter.py


注:本文中的django.db.models.PositiveIntegerField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。