本文整理匯總了Python中django.db.models.SlugField方法的典型用法代碼示例。如果您正苦於以下問題:Python models.SlugField方法的具體用法?Python models.SlugField怎麽用?Python models.SlugField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models
的用法示例。
在下文中一共展示了models.SlugField方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: document_field
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [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)
示例2: validate_field
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [as 別名]
def validate_field(self, errors, opts, f):
"""
MySQL has the following field length restriction:
No character (varchar) fields can have a length exceeding 255
characters if they have a unique index on them.
"""
varchar_fields = (models.CharField,
models.CommaSeparatedIntegerField,
models.SlugField)
if isinstance(f, varchar_fields) and f.max_length > 255 and f.unique:
msg = ('"%(name)s": %(cls)s cannot have a "max_length" greater '
'than 255 when using "unique=True".')
errors.add(opts, msg % {'name': f.name,
'cls': f.__class__.__name__})
示例3: test_descriptor_user_defined_primary_key
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [as 別名]
def test_descriptor_user_defined_primary_key(self):
"""Tests that descriptor works even when primary key is user
defined."""
model = get_fake_model(
dict(
slug=models.SlugField(primary_key=True), title=LocalizedField()
)
)
obj = model.objects.create(slug="test", title="test")
assert obj.title == "test"
示例4: test_slug
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [as 別名]
def test_slug(self):
field = self.get_field(Form, "slug")
self.assertModelField(field, models.SlugField)
self.assertEqual(field.max_length, 255)
self.assertTrue(field.allow_unicode)
self.assertTrue(field.unique)
示例5: validate_field
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [as 別名]
def validate_field(self, errors, opts, f):
"""
MySQL has the following field length restriction:
No character (varchar) fields can have a length exceeding 255
characters if they have a unique index on them.
"""
from django.db import models
varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
models.SlugField)
if (isinstance(f, varchar_fields) and f.unique
and (f.max_length is None or int(f.max_length) > 255)):
msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__})
示例6: test_should_slug_convert_string
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [as 別名]
def test_should_slug_convert_string():
assert_conversion(models.SlugField, graphene.String)
示例7: test_slug_field
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import SlugField [as 別名]
def test_slug_field(self):
field = models.SlugField()
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.SlugField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {})
field = models.SlugField(db_index=False, max_length=231)
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.SlugField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"db_index": False, "max_length": 231})