当前位置: 首页>>代码示例>>Python>>正文


Python forms.SlugField方法代码示例

本文整理汇总了Python中django.forms.SlugField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.SlugField方法的具体用法?Python forms.SlugField怎么用?Python forms.SlugField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.SlugField方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 50)
        # Set db_index=True unless it's been set manually.
        if 'db_index' not in kwargs:
            kwargs['db_index'] = True
        super(SlugField, self).__init__(*args, **kwargs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:__init__.py

示例2: deconstruct

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def deconstruct(self):
        name, path, args, kwargs = super(SlugField, self).deconstruct()
        if kwargs.get("max_length", None) == 50:
            del kwargs['max_length']
        if self.db_index is False:
            kwargs['db_index'] = False
        else:
            del kwargs['db_index']
        return name, path, args, kwargs 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:__init__.py

示例3: get_internal_type

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def get_internal_type(self):
        return "SlugField" 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:__init__.py

示例4: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:__init__.py

示例5: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super().formfield(**defaults) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:__init__.py

示例6: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def formfield(self, **kwargs):
        return super().formfield(**{
            'form_class': forms.SlugField,
            'allow_unicode': self.allow_unicode,
            **kwargs,
        }) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:8,代码来源:__init__.py

示例7: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 50)
        # Set db_index=True unless it's been set manually.
        if 'db_index' not in kwargs:
            kwargs['db_index'] = True
        self.allow_unicode = kwargs.pop('allow_unicode', False)
        if self.allow_unicode:
            self.default_validators = [validators.validate_unicode_slug]
        super(SlugField, self).__init__(*args, **kwargs) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:11,代码来源:__init__.py

示例8: deconstruct

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def deconstruct(self):
        name, path, args, kwargs = super(SlugField, self).deconstruct()
        if kwargs.get("max_length") == 50:
            del kwargs['max_length']
        if self.db_index is False:
            kwargs['db_index'] = False
        else:
            del kwargs['db_index']
        if self.allow_unicode is not False:
            kwargs['allow_unicode'] = self.allow_unicode
        return name, path, args, kwargs 
开发者ID:Yeah-Kun,项目名称:python,代码行数:13,代码来源:__init__.py

示例9: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:6,代码来源:__init__.py

示例10: test_should_slug_convert_string

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def test_should_slug_convert_string():
    assert_conversion(forms.SlugField, String) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:4,代码来源:test_converter.py

示例11: test_modelformset_factory_field_class_overrides

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def test_modelformset_factory_field_class_overrides(self):
        author = Author.objects.create(pk=1, name='Charles Baudelaire')
        BookFormSet = modelformset_factory(Book, fields="__all__", field_classes={
            'title': forms.SlugField,
        })
        form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
        self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
        self.assertIsInstance(form.fields['title'], forms.SlugField) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例12: test_inlineformset_factory_field_class_overrides

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def test_inlineformset_factory_field_class_overrides(self):
        author = Author.objects.create(pk=1, name='Charles Baudelaire')
        BookFormSet = inlineformset_factory(Author, Book, fields="__all__", field_classes={
            'title': forms.SlugField,
        })
        form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
        self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
        self.assertIsInstance(form.fields['title'], forms.SlugField) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例13: test_slugfield_normalization

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def test_slugfield_normalization(self):
        f = SlugField()
        self.assertEqual(f.clean('    aa-bb-cc    '), 'aa-bb-cc') 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_slugfield.py

示例14: test_slugfield_unicode_normalization

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SlugField [as 别名]
def test_slugfield_unicode_normalization(self):
        f = SlugField(allow_unicode=True)
        self.assertEqual(f.clean('a'), 'a')
        self.assertEqual(f.clean('1'), '1')
        self.assertEqual(f.clean('a1'), 'a1')
        self.assertEqual(f.clean('你好'), '你好')
        self.assertEqual(f.clean('  你-好  '), '你-好')
        self.assertEqual(f.clean('ıçğüş'), 'ıçğüş')
        self.assertEqual(f.clean('foo-ıç-bar'), 'foo-ıç-bar') 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_slugfield.py


注:本文中的django.forms.SlugField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。