US #55: Custom fields - Fix custo attribute serializer validator of name

remotes/origin/enhancement/email-actions
David Barragán Merino 2015-02-18 23:17:07 +01:00
parent df8c532cbd
commit 3369fa41f0
1 changed files with 5 additions and 1 deletions

View File

@ -41,14 +41,18 @@ class BaseCustomAttributeSerializer(ModelSerializer):
- update the name - update the name
- update the project (move to another project) - update the project (move to another project)
""" """
data_id = data.get("id", None)
data_name = data.get("name", None) data_name = data.get("name", None)
data_project = data.get("project", None) data_project = data.get("project", None)
if self.object: if self.object:
data_id = data_id or self.object.id
data_name = data_name or self.object.name data_name = data_name or self.object.name
data_project = data_project or self.object.project data_project = data_project or self.object.project
model = self.Meta.model model = self.Meta.model
qs = model.objects.filter(project=data_project, name=data_name) qs = (model.objects.filter(project=data_project, name=data_name)
.exclude(id=data_id))
if qs.exists(): if qs.exists():
raise ValidationError(_("There is a custom field with the same name in this project.")) raise ValidationError(_("There is a custom field with the same name in this project."))