validator modified

This commit is contained in:
Qwann 2016-10-17 19:40:31 +02:00
parent cc9fea5b14
commit f06ae696e5

View file

@ -1,5 +1,6 @@
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.validators import RegexValidator
from django.core import exceptions from django.core import exceptions
from django.db import models from django.db import models
from re import search as re_search from re import search as re_search
@ -72,10 +73,16 @@ class ActivityTag(models.Model):
is_public = models.BooleanField( is_public = models.BooleanField(
help_text=_("TODO"), help_text=_("TODO"),
) )
color_regex = RegexValidator(
regex=r'^#(?:[0-9a-fA-F]{3}){1,2}$',
message="La chaîne de caractère rentrée n'est pas"
"une couleur en hexadécimal.",
)
color = models.CharField( color = models.CharField(
_('Couleur'), _('Couleur'),
max_length=7, max_length=7,
validators=[validate_color], validators=[color_regex],
help_text="Rentrer une couleur en hexadécimal",
) )
class Meta: class Meta: