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


Python models.UUIDField方法代碼示例

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


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

示例1: define_projection_record_class

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [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: url_str_to_user_pk

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def url_str_to_user_pk(s):
    User = get_user_model()
    # TODO: Ugh, isn't there a cleaner way to determine whether or not
    # the PK is a str-like field?
    if getattr(User._meta.pk, 'rel', None):
        pk_field = User._meta.pk.rel.to._meta.pk
    else:
        pk_field = User._meta.pk
    if (hasattr(models, 'UUIDField') and issubclass(
            type(pk_field), models.UUIDField)):
        return s
    try:
        pk_field.to_python('a')
        pk = s
    except ValidationError:
        pk = base36_to_int(s)
    return pk 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:19,代碼來源:utils.py

示例3: test_serialize_uuid

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_serialize_uuid(self):
        self.assertSerializedEqual(uuid.uuid1())
        self.assertSerializedEqual(uuid.uuid4())

        uuid_a = uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8')
        uuid_b = uuid.UUID('c7853ec1-2ea3-4359-b02d-b54e8f1bcee2')
        self.assertSerializedResultEqual(
            uuid_a,
            ("uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8')", {'import uuid'})
        )
        self.assertSerializedResultEqual(
            uuid_b,
            ("uuid.UUID('c7853ec1-2ea3-4359-b02d-b54e8f1bcee2')", {'import uuid'})
        )

        field = models.UUIDField(choices=((uuid_a, 'UUID A'), (uuid_b, 'UUID B')), default=uuid_a)
        string = MigrationWriter.serialize(field)[0]
        self.assertEqual(
            string,
            "models.UUIDField(choices=["
            "(uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8'), 'UUID A'), "
            "(uuid.UUID('c7853ec1-2ea3-4359-b02d-b54e8f1bcee2'), 'UUID B')], "
            "default=uuid.UUID('5c859437-d061-4847-b3f7-e6b78852f8c8'))"
        ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:26,代碼來源:test_writer.py

示例4: user_pk_to_url_str

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def user_pk_to_url_str(user):
    """
    This should return a string.
    """
    User = get_user_model()
    if (hasattr(models, 'UUIDField') and issubclass(
            type(User._meta.pk), models.UUIDField)):
        if isinstance(user.pk, six.string_types):
            return user.pk
        return user.pk.hex

    ret = user.pk
    if isinstance(ret, six.integer_types):
        ret = int_to_base36(user.pk)
    return str(ret) 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:17,代碼來源:utils.py

示例5: setup_db_compat_django

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def setup_db_compat_django():
    from tri_table import register_column_factory
    try:
        # noinspection PyUnresolvedReferences
        from django.db.models import IntegerField, FloatField, TextField, BooleanField, AutoField, CharField, DateField, DateTimeField, DecimalField, EmailField, TimeField, ForeignKey, ManyToOneRel, ManyToManyField, ManyToManyRel, UUIDField
    except ImportError:
        pass
    else:
        # The order here is significant because of inheritance structure. More specific must be below less specific.

        register_column_factory(CharField, Shortcut(call_target__attribute='text'))
        register_column_factory(UUIDField, Shortcut(call_target__attribute='text'))
        register_column_factory(TimeField, Shortcut(call_target__attribute='time'))
        register_column_factory(EmailField, Shortcut(call_target__attribute='email'))
        register_column_factory(DecimalField, Shortcut(call_target__attribute='decimal'))
        register_column_factory(DateField, Shortcut(call_target__attribute='date'))
        register_column_factory(DateTimeField, Shortcut(call_target__attribute='datetime'))
        register_column_factory(BooleanField, Shortcut(call_target__attribute='boolean'))
        register_column_factory(TextField, Shortcut(call_target__attribute='text'))
        register_column_factory(FloatField, Shortcut(call_target__attribute='float'))
        register_column_factory(IntegerField, Shortcut(call_target__attribute='integer'))
        register_column_factory(AutoField, Shortcut(call_target__attribute='integer', show=False))
        register_column_factory(ManyToOneRel, None)
        register_column_factory(ManyToManyField, Shortcut(call_target__attribute='many_to_many'))
        register_column_factory(ManyToManyRel, None)

        register_column_factory(ForeignKey, Shortcut(call_target__attribute='foreign_key')) 
開發者ID:TriOptima,項目名稱:tri.table,代碼行數:29,代碼來源:db_compat.py

示例6: get_field_cls

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def get_field_cls(self, field):
        str_fields = (models.CharField, models.TextField, models.UUIDField)
        if isinstance(field, str_fields):
            return StrField
        elif isinstance(field, (models.AutoField, models.IntegerField)):
            return IntField
        elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
            return BoolField
        elif isinstance(field, (models.DecimalField, models.FloatField)):
            return FloatField
        elif isinstance(field, models.DateTimeField):
            return DateTimeField
        elif isinstance(field, models.DateField):
            return DateField
        return DjangoQLField 
開發者ID:ivelum,項目名稱:djangoql,代碼行數:17,代碼來源:schema.py

示例7: test_should_uuid_convert_id

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

示例8: test_update_UUIDField_using_Value

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_update_UUIDField_using_Value(self):
        UUID.objects.create()
        UUID.objects.update(uuid=Value(uuid.UUID('12345678901234567890123456789012'), output_field=UUIDField()))
        self.assertEqual(UUID.objects.get().uuid, uuid.UUID('12345678901234567890123456789012')) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:6,代碼來源:tests.py

示例9: test_update_uuid

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_update_uuid(self):
        CaseTestModel.objects.update(
            uuid=Case(
                # fails on sqlite if output_field is not set explicitly on all
                # Values containing UUIDs
                When(integer=1, then=Value(
                    UUID('11111111111111111111111111111111'),
                    output_field=models.UUIDField(),
                )),
                When(integer=2, then=Value(
                    UUID('22222222222222222222222222222222'),
                    output_field=models.UUIDField(),
                )),
            ),
        )
        self.assertQuerysetEqual(
            CaseTestModel.objects.all().order_by('pk'),
            [
                (1, UUID('11111111111111111111111111111111')),
                (2, UUID('22222222222222222222222222222222')),
                (3, None),
                (2, UUID('22222222222222222222222222222222')),
                (3, None),
                (3, None),
                (4, None),
            ],
            transform=attrgetter('integer', 'uuid')
        ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:30,代碼來源:tests.py

示例10: get_pk_description

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def get_pk_description(model, model_field):
    if isinstance(model_field, models.AutoField):
        value_type = _('unique integer value')
    elif isinstance(model_field, models.UUIDField):
        value_type = _('UUID string')
    else:
        value_type = _('unique value')

    return _('A {value_type} identifying this {name}.').format(
        value_type=value_type,
        name=model._meta.verbose_name,
    ) 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:14,代碼來源:inspectors.py

示例11: test_deconstruct

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_deconstruct(self):
        field = models.UUIDField()
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(kwargs, {}) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:test_uuid.py

示例12: test_to_python

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_to_python(self):
        self.assertIsNone(models.UUIDField().to_python(None)) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_uuid.py

示例13: test_invalid_uuid

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_invalid_uuid(self):
        field = models.UUIDField()
        with self.assertRaises(exceptions.ValidationError) as cm:
            field.clean('550e8400', None)
        self.assertEqual(cm.exception.code, 'invalid')
        self.assertEqual(cm.exception.message % cm.exception.params, "'550e8400' is not a valid UUID.") 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:test_uuid.py

示例14: test_label_and_url_for_value_invalid_uuid

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_label_and_url_for_value_invalid_uuid(self):
        field = Bee._meta.get_field('honeycomb')
        self.assertIsInstance(field.target_field, UUIDField)
        widget = widgets.ForeignKeyRawIdWidget(field.remote_field, admin.site)
        self.assertEqual(widget.label_and_url_for_value('invalid-uuid'), ('', '')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例15: test_to_python_int_values

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import UUIDField [as 別名]
def test_to_python_int_values(self):
        self.assertEqual(
            models.UUIDField().to_python(0),
            uuid.UUID('00000000-0000-0000-0000-000000000000')
        )
        # Works for integers less than 128 bits.
        self.assertEqual(
            models.UUIDField().to_python((2 ** 128) - 1),
            uuid.UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_uuid.py


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