Validate project slug to be unique
parent
9c5bb7ff55
commit
558ac79c5d
|
@ -99,6 +99,11 @@ class ProjectSerializer(serializers.ModelSerializer):
|
||||||
# The "stars_count" attribute is attached in the get_queryset of the viewset.
|
# The "stars_count" attribute is attached in the get_queryset of the viewset.
|
||||||
return getattr(obj, "stars_count", 0)
|
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):
|
class ProjectDetailSerializer(ProjectSerializer):
|
||||||
roles = serializers.SerializerMethodField("get_list_of_roles")
|
roles = serializers.SerializerMethodField("get_list_of_roles")
|
||||||
|
|
Loading…
Reference in New Issue