mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 09:42:10 +01:00 
			
		
		
		
	Better unique validation errors
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -26,7 +26,7 @@ class TeamForm(forms.ModelForm):
 | 
			
		||||
    def clean_name(self):
 | 
			
		||||
        if "name" in self.cleaned_data:
 | 
			
		||||
            name = self.cleaned_data["name"]
 | 
			
		||||
            if not self.instance.pk and Team.objects.filter(name=name).exists():
 | 
			
		||||
            if Team.objects.filter(name=name).exclude(pk=self.instance.pk).exists():
 | 
			
		||||
                raise ValidationError(_("This name is already used."))
 | 
			
		||||
            return name
 | 
			
		||||
 | 
			
		||||
@@ -36,7 +36,7 @@ class TeamForm(forms.ModelForm):
 | 
			
		||||
            if not re.match("[A-Z]{3}", trigram):
 | 
			
		||||
                raise ValidationError(_("The trigram must be composed of three uppercase letters."))
 | 
			
		||||
 | 
			
		||||
            if not self.instance.pk and Team.objects.filter(trigram=trigram).exists():
 | 
			
		||||
            if Team.objects.filter(trigram=trigram).exclude(pk=self.instance.pk).exists():
 | 
			
		||||
                raise ValidationError(_("This trigram is already used."))
 | 
			
		||||
            return trigram
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user