Skip to content

Commit

Permalink
Formatted blogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anupamaraie committed Nov 4, 2023
1 parent 0d1187a commit 4a1e0b9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions blogs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Posts(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='post'
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="post"
) #reference from Users

def __str__(self):
Expand All @@ -23,10 +23,10 @@ def __str__(self):

class Comments(models.Model):
post = models.ForeignKey(
Posts, on_delete= models.CASCADE,related_name='comment_post'
Posts, on_delete= models.CASCADE,related_name="comment_post"
) #reference from Posts
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete= models.CASCADE, related_name='comment_user'
settings.AUTH_USER_MODEL, on_delete= models.CASCADE, related_name="comment_user"
) #reference from Users
c_content = models.TextField()
created_at = models.DateTimeField(auto_now=True)
Expand All @@ -37,9 +37,9 @@ def __str__(self):

class Likes(models.Model):
post = models.ForeignKey(
Posts, on_delete= models.CASCADE, related_name='like_post'
Posts, on_delete= models.CASCADE, related_name="like_post"
) #refrence from Posts
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete= models.CASCADE, related_name='like_user'
settings.AUTH_USER_MODEL, on_delete= models.CASCADE, related_name="like_user"
) #reference from Users
created_at = models.DateTimeField(auto_now=True)
8 changes: 4 additions & 4 deletions blogs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Meta:
model = Likes
fields = "__all__"

read_only_fields = ["user","post"]
read_only_fields = ["user", "post"]


class CommentSerializer(serializers.ModelSerializer):
Expand All @@ -27,7 +27,7 @@ class Meta:
model = Comments
fields = "__all__"

read_only_fields = ["user","post"]
read_only_fields = ["user", "post"]


class PostSerializer(serializers.ModelSerializer):
Expand All @@ -46,12 +46,12 @@ class Meta:
"updated_at",
"comment_post",
"like_post",
)
)


class CreatePostSerializer(serializers.ModelSerializer):
class Meta:
model = Posts
fields = ("user","title","content")
fields = ("user", "title", "content")

read_only_fields = ["user"]
2 changes: 1 addition & 1 deletion blogs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GetBlogView,
LikeCreateView,
ReadCommentView,
ReadPostView
ReadPostView,
)

urlpatterns = [
Expand Down
7 changes: 4 additions & 3 deletions blogs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CommentSerializer,
CreatePostSerializer,
LikeSerializer,
PostSerializer
PostSerializer,
)
from core.response import CustomResponse as cr

Expand All @@ -37,7 +37,7 @@ def get(self, request: Request) -> Response:


class CreateBlogView(APIView):
permission_classes=[IsAuthenticated]
permission_classes = [IsAuthenticated]

serializer_class = CreatePostSerializer

Expand Down Expand Up @@ -123,7 +123,7 @@ def post(self, request: Request) -> Response:

return cr.success(
data=serializer.data, message="New comment added successfully!"
)
)

def delete(self, request: Request, id) -> Response:
"""
Expand Down Expand Up @@ -171,6 +171,7 @@ def put(self, request: Request, id) -> Response:

return cr.success(data=serializer.data, message="Comment updated successfully!")


class ReadPostView(APIView):
serializer_class = PostSerializer

Expand Down

0 comments on commit 4a1e0b9

Please sign in to comment.