Python django.forms.SlugField() Examples

The following are 30 code examples for showing how to use django.forms.SlugField(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.forms , or try the search function .

Example 1
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
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) 
Example 2
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
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 
Example 3
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 4
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example 5
Project: bioforum   Author: reBiocoder   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 6
Project: bioforum   Author: reBiocoder   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super().formfield(**defaults) 
Example 7
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 8
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        return super().formfield(**{
            'form_class': forms.SlugField,
            'allow_unicode': self.allow_unicode,
            **kwargs,
        }) 
Example 9
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
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) 
Example 10
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 11
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 12
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example 13
Project: luscan-devel   Author: blackye   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
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) 
Example 14
Project: luscan-devel   Author: blackye   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 15
Project: luscan-devel   Author: blackye   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example 16
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
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) 
Example 17
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 18
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 19
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example 20
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
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) 
Example 21
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
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 
Example 22
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example 23
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example 24
Project: graphene-django   Author: graphql-python   File: test_converter.py    License: MIT License 5 votes vote down vote up
def test_should_slug_convert_string():
    assert_conversion(forms.SlugField, String) 
Example 25
Project: djongo   Author: nesdis   File: tests.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example 26
Project: djongo   Author: nesdis   File: tests.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example 27
Project: djongo   Author: nesdis   File: test_slugfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_slugfield_normalization(self):
        f = SlugField()
        self.assertEqual(f.clean('    aa-bb-cc    '), 'aa-bb-cc') 
Example 28
Project: djongo   Author: nesdis   File: test_slugfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example 29
Project: djongo   Author: nesdis   File: tests.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example 30
Project: djongo   Author: nesdis   File: test_slugfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_slugfield_normalization(self):
        f = SlugField()
        self.assertEqual(f.clean('    aa-bb-cc    '), 'aa-bb-cc')