Skip to content

Commit 4d0f717

Browse files
committed
start comment feature
1 parent c379992 commit 4d0f717

File tree

10 files changed

+61
-3
lines changed

10 files changed

+61
-3
lines changed

Test templates/blog.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>Blog Page</title>
77
<script>
88
const bloggit_conf = {
9-
"api_key": "e9f51a0a6cc0494cb5525d9e8def7337",
9+
"api_key": "7070aa3bfb7a4f6f8266fa44180d4aaf",
1010
"cont_rend":"classic",
1111
"header": {
1212
"type": "milky-way",
@@ -23,8 +23,7 @@
2323
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
2424
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
2525
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
26-
<!-- <script src="./Javascript/home_and_blog.js"></script> -->
27-
<script src = "https://bloggit.pythonanywhere.com/static/Javascript/config.js"></script>
26+
<script src="./Javascript/home_and_blog.js"></script>
2827
</head>
2928
<body>
3029
<section id="bloggit-header">

comments/__init__.py

Whitespace-only changes.

comments/admin.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.contrib import admin
2+
from .models import Comment
3+
4+
# Register your models here.
5+
6+
class CommentAdmin(admin.ModelAdmin):
7+
list_display = ["post",'name', "email"]
8+
9+
admin.site.register(Comment, CommentAdmin)

comments/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CommentsConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "comments"

comments/models.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.db import models
2+
from tinymce.models import HTMLField
3+
from api.models import Post
4+
5+
# Create your models here.
6+
7+
class Comment(models.Model):
8+
post = models.OneToOneField(Post, related_name='post', on_delete=models.CASCADE)
9+
name = models.CharField(max_length=100)
10+
email = models.EmailField()
11+
comment = HTMLField()
12+
13+
def __str__(self):
14+
return str(self.post)

comments/serializers.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from rest_framework.serializers import ModelSerializer
2+
from .models import *
3+
from rest_framework.validators import ValidationError
4+
5+
class CommentSerializer(ModelSerializer):
6+
class Meta:
7+
model = Comment
8+
fields = "__all__"
9+
10+
def validate_comment(self, value):
11+
if value.strip() == "":
12+
raise ValidationError("Comment can't be empty!")
13+
return value

comments/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

comments/views.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.shortcuts import render
2+
from rest_framework.decorators import APIView
3+
from rest_framework.generics import GenericAPIView
4+
from rest_framework.permissions import AllowAny
5+
from .serializers import *
6+
from .models import *
7+
8+
9+
# Create your views here.
10+
class CommentView(GenericAPIView):
11+
serializer_class = CommentSerializer
12+
queryset = Comment.objects.all()
13+
permission_classes = [AllowAny]

core/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'api',
4444
"userprofile",
4545
"app",
46+
"comments",
4647

4748

4849
# dependencies

db.sqlite3

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)