A library for adding comments to models using Django REST Framework.
Project description
DRF-Commnts
A library for adding comments to models using Django REST Framework.
Installation
pip install drf-comments
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.1.tar.gz
(2.7 kB
view details)
Built Distribution
File details
Details for the file drf-comments-1.2.1.tar.gz
.
File metadata
- Download URL: drf-comments-1.2.1.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 | 740246f32cbbf2208e00c56c4515d2c757eaf082134ca2a464caf74c6e7a9c4d |
|
MD5 | b2ca7b5ed26cadec63a2846d43b81ab2 |
|
BLAKE2b-256 | fb0f88b097e6d1a72968cb80da8896bb467a8d7ba99eb7ab0c06a2c21acb5300 |
File details
Details for the file drf_comments-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: drf_comments-1.2.1-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 | dabfed6d248e73631c14330ec83111b752befedff7cfefaa0ecc332a1a5df495 |
|
MD5 | 39f16b7b677fdf8d99170580ba86d993 |
|
BLAKE2b-256 | daa2ac459d84411456a187df28b1c8eaad51c8d3e779f2b2043c73fefa050e5a |