A library for adding comments to models using Django REST Framework.
Project description
My Comment Library
A library for adding comments to models using Django REST Framework.
Installation
pip install my_comment_library
Usage
from drf_comments.comments import BaseComment, CommentViewSet, comment_serializer, create_comment_serializer
# Define your models
class Post(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=255)
content = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.title
class PostComment(BaseComment):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
class Meta(BaseComment.Meta):
db_table = 'posts_postcomment'
verbose_name = 'Post Comment'
verbose_name_plural = 'Post Comments'
# Define your serializers
class PostSerializer(serializers.ModelSerializer):
class Meta:
model = Post
fields = ['id', 'user', 'title', 'content', 'created_at', 'updated_at']
PostCommentSerializer = comment_serializer(PostComment)
PostCommentCreateSerializer = create_comment_serializer(PostComment)
# Define your viewsets
class PostViewSet(viewsets.ModelViewSet):
queryset = Post.objects.all()
serializer_class = PostSerializer
permission_classes = [IsAuthenticated]
authentication_classes = [TokenAuthentication]
class PostCommentViewSet(CommentViewSet):
queryset = PostComment.objects.all()
serializer_class = PostCommentSerializer
create_serializer_class = PostCommentCreateSerializer
permission_classes = [IsAuthenticated]
authentication_classes = [TokenAuthentication]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
drf-comments-1.2.tar.gz
(2.7 kB
view details)
Built Distribution
File details
Details for the file drf-comments-1.2.tar.gz
.
File metadata
- Download URL: drf-comments-1.2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f01dd5c24da7d6060b8b65a3690c7b0cc6b13bf21ee6705f24f7e2714f5c6381 |
|
MD5 | 9b9008a19a5d79d53784b65be3d7b2cb |
|
BLAKE2b-256 | 33122a519e489df9c200e2a318982d6c46225b52cdaa0329dcea99beb7cc223e |
File details
Details for the file drf_comments-1.2-py3-none-any.whl
.
File metadata
- Download URL: drf_comments-1.2-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2b30efc0f69855306287712bf854f4e8184199aa243c91dd61cb1730c5d1773 |
|
MD5 | 03dba50ae9a25aa93d7a589d1a575a45 |
|
BLAKE2b-256 | 8b9aff3672076b137fb9221201eb4565119af66716a8ad90bd4d9e4c6b592595 |