本文整理汇总了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
示例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
示例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'))"
)
示例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)
示例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'))
示例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
示例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)
示例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'))
示例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')
)
示例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,
)
示例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, {})
示例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))
示例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.")
示例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'), ('', ''))
示例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')
)