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


Python models.BigAutoField方法代碼示例

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


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

示例1: define_projection_record_class

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def define_projection_record_class(self):
        class ProjectionRecord(models.Model):
            uid = models.BigAutoField(primary_key=True)

            # Sequence ID (e.g. an entity or aggregate ID).
            projection_id = models.UUIDField()

            # State of the item (serialized dict, possibly encrypted).
            state = models.TextField()

            class Meta:
                db_table = "projections"
                app_label = "projections"
                managed = False

        self.projection_record_class = ProjectionRecord 
開發者ID:johnbywater,項目名稱:eventsourcing,代碼行數:18,代碼來源:test_process_with_django.py

示例2: test_bulk_upsert_return_models

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_bulk_upsert_return_models():
    """Tests whether models are returned instead of dictionaries when
    specifying the return_model=True argument."""

    model = get_fake_model(
        {
            "id": models.BigAutoField(primary_key=True),
            "name": models.CharField(max_length=255, unique=True),
        }
    )

    rows = [dict(name="John Smith"), dict(name="Jane Doe")]

    objs = model.objects.bulk_upsert(
        conflict_target=["name"], rows=rows, return_model=True
    )

    for index, obj in enumerate(objs, 1):
        assert isinstance(obj, model)
        assert obj.id == index 
開發者ID:SectorLabs,項目名稱:django-postgres-extra,代碼行數:22,代碼來源:test_upsert.py

示例3: test_bulk_return_models

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_bulk_return_models(conflict_action):
    """Tests whether models are returned instead of dictionaries when
    specifying the return_model=True argument."""

    model = get_fake_model(
        {
            "id": models.BigAutoField(primary_key=True),
            "name": models.CharField(max_length=255, unique=True),
        }
    )

    rows = [dict(name="John Smith"), dict(name="Jane Doe")]

    objs = model.objects.on_conflict(["name"], conflict_action).bulk_insert(
        rows, return_model=True
    )

    for index, obj in enumerate(objs, 1):
        assert isinstance(obj, model)
        assert obj.id == index 
開發者ID:SectorLabs,項目名稱:django-postgres-extra,代碼行數:22,代碼來源:test_on_conflict.py

示例4: test_cast_to_integer

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_cast_to_integer(self):
        for field_class in (
            models.AutoField,
            models.BigAutoField,
            models.IntegerField,
            models.BigIntegerField,
            models.SmallIntegerField,
            models.PositiveIntegerField,
            models.PositiveSmallIntegerField,
        ):
            with self.subTest(field_class=field_class):
                numbers = Author.objects.annotate(cast_int=Cast('alias', field_class()))
                self.assertEqual(numbers.get().cast_int, 1) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:15,代碼來源:test_cast.py

示例5: test_bulk_upsert_accepts_getitem_iterable

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_bulk_upsert_accepts_getitem_iterable():
    """Tests whether an iterable only implementing the __getitem__ method works
    correctly."""

    class GetItemIterable:
        def __init__(self, items):
            self.items = items

        def __getitem__(self, key):
            return self.items[key]

    model = get_fake_model(
        {
            "id": models.BigAutoField(primary_key=True),
            "name": models.CharField(max_length=255, unique=True),
        }
    )

    rows = GetItemIterable([dict(name="John Smith"), dict(name="Jane Doe")])

    objs = model.objects.bulk_upsert(
        conflict_target=["name"], rows=rows, return_model=True
    )

    for index, obj in enumerate(objs, 1):
        assert isinstance(obj, model)
        assert obj.id == index 
開發者ID:SectorLabs,項目名稱:django-postgres-extra,代碼行數:29,代碼來源:test_upsert.py

示例6: test_bulk_upsert_accepts_iter_iterable

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_bulk_upsert_accepts_iter_iterable():
    """Tests whether an iterable only implementing the __iter__ method works
    correctly."""

    class IterIterable:
        def __init__(self, items):
            self.items = items

        def __iter__(self):
            return iter(self.items)

    model = get_fake_model(
        {
            "id": models.BigAutoField(primary_key=True),
            "name": models.CharField(max_length=255, unique=True),
        }
    )

    rows = IterIterable([dict(name="John Smith"), dict(name="Jane Doe")])

    objs = model.objects.bulk_upsert(
        conflict_target=["name"], rows=rows, return_model=True
    )

    for index, obj in enumerate(objs, 1):
        assert isinstance(obj, model)
        assert obj.id == index 
開發者ID:SectorLabs,項目名稱:django-postgres-extra,代碼行數:29,代碼來源:test_upsert.py

示例7: test_bulk_return

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_bulk_return():
    """Tests if primary keys are properly returned from 'bulk_insert'."""

    model = get_fake_model(
        {
            "id": models.BigAutoField(primary_key=True),
            "name": models.CharField(max_length=255, unique=True),
        }
    )

    rows = [dict(name="John Smith"), dict(name="Jane Doe")]

    objs = model.objects.on_conflict(
        ["name"], ConflictAction.UPDATE
    ).bulk_insert(rows)

    for index, obj in enumerate(objs, 1):
        assert obj["id"] == index

    # Add objects again, update should return the same ids
    # as we're just updating.
    objs = model.objects.on_conflict(
        ["name"], ConflictAction.UPDATE
    ).bulk_insert(rows)

    for index, obj in enumerate(objs, 1):
        assert obj["id"] == index 
開發者ID:SectorLabs,項目名稱:django-postgres-extra,代碼行數:29,代碼來源:test_on_conflict.py

示例8: test_model_with_bigautofield

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import BigAutoField [as 別名]
def test_model_with_bigautofield(self):
        """
        A model with BigAutoField can be created.
        """
        def create_data(models, schema_editor):
            Author = models.get_model("test_author", "Author")
            Book = models.get_model("test_book", "Book")
            author1 = Author.objects.create(name="Hemingway")
            Book.objects.create(title="Old Man and The Sea", author=author1)
            Book.objects.create(id=2 ** 33, title="A farewell to arms", author=author1)

            author2 = Author.objects.create(id=2 ** 33, name="Remarque")
            Book.objects.create(title="All quiet on the western front", author=author2)
            Book.objects.create(title="Arc de Triomphe", author=author2)

        create_author = migrations.CreateModel(
            "Author",
            [
                ("id", models.BigAutoField(primary_key=True)),
                ("name", models.CharField(max_length=100)),
            ],
            options={},
        )
        create_book = migrations.CreateModel(
            "Book",
            [
                ("id", models.BigAutoField(primary_key=True)),
                ("title", models.CharField(max_length=100)),
                ("author", models.ForeignKey(to="test_author.Author", on_delete=models.CASCADE))
            ],
            options={},
        )
        fill_data = migrations.RunPython(create_data)

        project_state = ProjectState()
        new_state = project_state.clone()
        with connection.schema_editor() as editor:
            create_author.state_forwards("test_author", new_state)
            create_author.database_forwards("test_author", editor, project_state, new_state)

        project_state = new_state
        new_state = new_state.clone()
        with connection.schema_editor() as editor:
            create_book.state_forwards("test_book", new_state)
            create_book.database_forwards("test_book", editor, project_state, new_state)

        project_state = new_state
        new_state = new_state.clone()
        with connection.schema_editor() as editor:
            fill_data.state_forwards("fill_data", new_state)
            fill_data.database_forwards("fill_data", editor, project_state, new_state) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:53,代碼來源:test_operations.py


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