Validate project slug to be unique

remotes/origin/enhancement/email-actions
Anler Hp 2014-07-07 13:46:31 +02:00
parent 9c5bb7ff55
commit 558ac79c5d
1 changed files with 5 additions and 0 deletions

View File

@ -99,6 +99,11 @@ class ProjectSerializer(serializers.ModelSerializer):
# The "stars_count" attribute is attached in the get_queryset of the viewset.
return getattr(obj, "stars_count", 0)
def validate_slug(self, attrs, source):
project_with_slug = models.Project.objects.filter(slug=attrs[source])
if source == "slug" and project_with_slug.exists():
raise serializers.ValidationError(_("Slug duplicated for the project"))
class ProjectDetailSerializer(ProjectSerializer):
roles = serializers.SerializerMethodField("get_list_of_roles")