Skip to content

Commit

Permalink
Merge pull request #4 from Cellou404/refac_blog
Browse files Browse the repository at this point in the history
validate overview
  • Loading branch information
Cellou404 authored Sep 2, 2024
2 parents c262dbb + 5089439 commit 955998c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions blog/serializers/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def get_comments_count(self, post) -> int:
comments = Comment.objects.filter(post=post).count()
return comments

def validate_overview(self, value):
if len(value) > 500:
raise serializers.ValidationError("Overview must be less than 500 characters")
return value

def create(self, validated_data):
author = self.context["author"]
post = Post.objects.create(author=author, **validated_data)
Expand Down

0 comments on commit 955998c

Please sign in to comment.