Validating name on userstory status

remotes/origin/enhancement/email-actions
Alejandro Alonso 2014-07-22 10:11:38 +02:00
parent 63ca789815
commit 136eb02cae
1 changed files with 17 additions and 0 deletions

View File

@ -37,6 +37,23 @@ class UserStoryStatusSerializer(serializers.ModelSerializer):
class Meta:
model = models.UserStoryStatus
def validate_name(self, attrs, source):
"""
Check the status name is not duplicated in the project on creation
"""
qs = None
# If the milestone exists:
if self.object and attrs.get("name", None):
qs = models.UserStoryStatus.objects.filter(project=self.object.project, name=attrs[source])
if not self.object and attrs.get("project", None) and attrs.get("name", None):
qs = models.UserStoryStatus.objects.filter(project=attrs["project"], name=attrs[source])
if qs and qs.exists():
raise serializers.ValidationError("Name duplicated for the project")
return attrs
# Task common serializers