mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-03-16 22:40:26 +00:00
chore: remove unused EavSlugField
This commit is contained in:
parent
8c183333d1
commit
31e12a0ef9
2 changed files with 1 additions and 38 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
|
@ -7,41 +5,6 @@ from django.utils.translation import gettext_lazy as _
|
|||
from eav.forms import CSVFormField
|
||||
|
||||
|
||||
class EavSlugField(models.SlugField):
|
||||
"""
|
||||
The slug field used by :class:`~eav.models.Attribute`
|
||||
"""
|
||||
|
||||
def validate(self, value, instance):
|
||||
"""
|
||||
Slugs are used to convert the Python attribute name to a database
|
||||
lookup and vice versa. We need it to be a valid Python identifier. We
|
||||
don't want it to start with a '_', underscore will be used in
|
||||
variables we don't want to be saved in the database.
|
||||
"""
|
||||
super(EavSlugField, self).validate(value, instance)
|
||||
slug_regex = r'^[a-z0-9]+(?:-[a-z0-9]+)*$'
|
||||
|
||||
if not re.match(slug_regex, value):
|
||||
raise ValidationError(
|
||||
_(
|
||||
'Must be all lower case, start with a letter, and contain '
|
||||
'only letters, numbers, or underscores.'
|
||||
)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def create_slug_from_name(name):
|
||||
"""Creates a slug based on the name."""
|
||||
name = name.strip().lower()
|
||||
|
||||
# Change spaces to underscores.
|
||||
name = '_'.join(name.split())
|
||||
|
||||
# Remove non alphanumeric characters.
|
||||
return re.sub('[^\w]', '', name)
|
||||
|
||||
|
||||
class EavDatatypeField(models.CharField):
|
||||
"""
|
||||
The datatype field used by :class:`~eav.models.Attribute`.
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Migration(migrations.Migration):
|
|||
),
|
||||
(
|
||||
'slug',
|
||||
eav.fields.EavSlugField(
|
||||
models.SlugField(
|
||||
help_text='Short unique attribute label',
|
||||
unique=True,
|
||||
verbose_name='Slug',
|
||||
|
|
|
|||
Loading…
Reference in a new issue