def _validate_python(self, value, state=None):
if len(value) > self.max_length:
raise ValidationError('toolong', self)
name_slug = slugify(value)
# Check for duplicates in the database
try:
CompanyAlchemy.get_company(name_slug)
except NoResultFound:
# There are no duplicates, the validation is therefore successful
pass
else:
# This company slug name is already present in the database, notify
# the user that the company he's trying to register already exists.
raise ValidationError('already_exists', self)
评论列表
文章目录