├── README.md
├── comment
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-38.pyc
│ ├── admin.cpython-38.pyc
│ ├── apps.cpython-38.pyc
│ ├── forms.cpython-38.pyc
│ ├── models.cpython-38.pyc
│ └── views.cpython-38.pyc
├── admin.py
├── apps.py
├── forms.py
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_comment.py
│ ├── 0003_auto_20210807_1825.py
│ ├── __init__.py
│ └── __pycache__
│ │ ├── 0001_initial.cpython-38.pyc
│ │ ├── 0002_comment.cpython-38.pyc
│ │ ├── 0003_auto_20210807_1825.cpython-38.pyc
│ │ └── __init__.cpython-38.pyc
├── models.py
├── templates
│ └── html
│ │ ├── allPost.html
│ │ ├── core.html
│ │ ├── home.html
│ │ └── singlePost.html
├── tests.py
└── views.py
├── db.sqlite3
├── manage.py
└── post
├── __init__.py
├── __pycache__
├── __init__.cpython-38.pyc
├── settings.cpython-38.pyc
├── urls.cpython-38.pyc
└── wsgi.cpython-38.pyc
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
/README.md:
--------------------------------------------------------------------------------
1 | # Roadmap To Build A Comment System
2 | 1. Create a model to save the comments.
3 | 2. Create a form to submit comments and validate the input data.
4 | 3. Add a view that processes the form and saves the new comment to the database.
5 | 4. Edit the post detail template to display the list of comments and the form to add a new comment.
6 |
--------------------------------------------------------------------------------
/comment/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__init__.py
--------------------------------------------------------------------------------
/comment/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/__pycache__/admin.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__pycache__/admin.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/__pycache__/apps.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__pycache__/apps.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/__pycache__/forms.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__pycache__/forms.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/__pycache__/models.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__pycache__/models.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/__pycache__/views.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/__pycache__/views.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from .models import Post,Comment
3 | # Register your models here.
4 | @admin.register(Post)
5 | class PostAdmin(admin.ModelAdmin):
6 | list_display = ['title','id']
7 |
8 | @admin.register(Comment)
9 | class CommentAdmin(admin.ModelAdmin):
10 | list_display = ['comments','id','name','post']
--------------------------------------------------------------------------------
/comment/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class CommentConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'comment'
7 |
--------------------------------------------------------------------------------
/comment/forms.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 | from django.forms import fields, widgets
3 | from .models import Post,Comment
4 | from django import forms
5 | class PostForm(forms.ModelForm):
6 | class Meta:
7 | model = Post
8 | fields = ['title','description']
9 | widgets ={
10 | 'title':forms.TextInput(attrs={'class':'form-control'}),
11 |
12 | }
13 |
14 | class CommentForm(forms.ModelForm):
15 | class Meta:
16 | model = Comment
17 | fields = ['name','comments']
18 | widgets = {
19 | 'name':forms.TextInput(attrs={'class':'form-control'}),
20 | 'comments':forms.TextInput(attrs={'class':'form-control'}),
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/comment/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.2.6 on 2021-08-07 10:41
2 |
3 | import ckeditor.fields
4 | from django.db import migrations, models
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | initial = True
10 |
11 | dependencies = [
12 | ]
13 |
14 | operations = [
15 | migrations.CreateModel(
16 | name='Post',
17 | fields=[
18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19 | ('title', models.CharField(max_length=100)),
20 | ('description', ckeditor.fields.RichTextField()),
21 | ],
22 | ),
23 | ]
24 |
--------------------------------------------------------------------------------
/comment/migrations/0002_comment.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.2.6 on 2021-08-07 12:24
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('comment', '0001_initial'),
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Comment',
16 | fields=[
17 | ('id', models.AutoField(primary_key=True, serialize=False)),
18 | ('comment', models.TextField()),
19 | ('name', models.CharField(max_length=100)),
20 | ('time', models.DateTimeField(auto_now=True)),
21 | ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='comment.post')),
22 | ],
23 | ),
24 | ]
25 |
--------------------------------------------------------------------------------
/comment/migrations/0003_auto_20210807_1825.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.2.6 on 2021-08-07 12:40
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('comment', '0002_comment'),
11 | ]
12 |
13 | operations = [
14 | migrations.RenameField(
15 | model_name='comment',
16 | old_name='comment',
17 | new_name='comments',
18 | ),
19 | migrations.AddField(
20 | model_name='comment',
21 | name='parent',
22 | field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='comment.comment'),
23 | ),
24 | ]
25 |
--------------------------------------------------------------------------------
/comment/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/migrations/__init__.py
--------------------------------------------------------------------------------
/comment/migrations/__pycache__/0001_initial.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/migrations/__pycache__/0001_initial.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/migrations/__pycache__/0002_comment.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/migrations/__pycache__/0002_comment.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/migrations/__pycache__/0003_auto_20210807_1825.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/migrations/__pycache__/0003_auto_20210807_1825.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/migrations/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/comment/migrations/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/comment/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 | from ckeditor.fields import RichTextField
3 |
4 | # Create your models here.
5 | class Post(models.Model):
6 | title = models.CharField(max_length=100)
7 | description = RichTextField()
8 |
9 | class Comment(models.Model):
10 | id = models.AutoField(primary_key=True)
11 | comments = models.TextField()
12 | name = models.CharField(max_length=100)
13 | post = models.ForeignKey(Post,on_delete=models.CASCADE)
14 | parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
15 | time = models.DateTimeField(auto_now=True)
16 |
--------------------------------------------------------------------------------
/comment/templates/html/allPost.html:
--------------------------------------------------------------------------------
1 | {% extends 'html/core.html' %}
2 | {% block content %}
3 | {% comment %} {% for data in all_data %}
4 | {{data}}
5 | {% endfor %} {% endcomment %}
6 |
7 |
8 |
9 | {% for data in all_data %}
10 |
11 |
{{data.title}}
12 |
13 | {{data.description |safe |slice:":120"}}
14 |
15 |
16 |
View All
17 |
18 | {% endfor %}
19 |
20 |
21 | {% endblock content %}
--------------------------------------------------------------------------------
/comment/templates/html/core.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Post!
12 |
13 |
14 |
15 | {% block content %}{% endblock content %}
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
29 |
--------------------------------------------------------------------------------
/comment/templates/html/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'html/core.html' %}
2 | {% load static %}
3 | {% block content %}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
18 |
19 |
20 |
21 |
22 |
23 | {% endblock content %}
24 |
25 |
26 |
--------------------------------------------------------------------------------
/comment/templates/html/singlePost.html:
--------------------------------------------------------------------------------
1 | {% extends 'html/core.html' %}
2 | {% block content %}
3 |
4 |
5 |
{{data.title}}
6 |
7 | {{data.description |safe}}
8 |
9 |
10 |
11 |
12 |
13 | {% comment %} comments {% endcomment %}
14 |
Comments:({{count}})
15 |
16 |
17 | {% comment %} comment form {% endcomment %}
18 |
24 |
25 |
26 |
27 | {% comment %} display comments {% endcomment %}
28 | {% for cm in comment %}
29 |
30 |
31 |
32 | {{cm.name}}
33 |
34 |
35 | {{cm.comments}}
36 |
37 |
38 | {% comment %} reply part {% endcomment %}
39 |
40 |
41 |
42 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
63 |
64 | {% if reply %}
65 | {% for re in reply %}
66 |
67 | {% if re.parent in comment %}
68 |
69 |
70 | {{re.name}}
71 |
72 |
73 | {{re.comments}}
74 |
75 |
76 |
77 | {% endif %}
78 |
79 | {% endfor %}
80 |
81 | {% endif %}
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | {% endfor %}
91 |
92 |
93 |
94 | {% endblock content %}
--------------------------------------------------------------------------------
/comment/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/comment/views.py:
--------------------------------------------------------------------------------
1 | from django import forms
2 | from django.http.response import HttpResponseRedirect
3 | from django.shortcuts import render, resolve_url
4 | from .forms import PostForm,CommentForm
5 | from .models import Comment, Post
6 | # Create your views here.
7 | def homeFunction(request):
8 | if request.method == 'POST':
9 | form = PostForm(request.POST)
10 | if form.is_valid():
11 | form.save()
12 | return HttpResponseRedirect('/')
13 | else:
14 | form = PostForm()
15 | return render(request,'html/home.html',{'form':form})
16 |
17 | def allPostFunction(request):
18 | all_data = Post.objects.all()
19 | return render(request,'html/allPost.html',{'all_data':all_data})
20 |
21 | def singlePost(request,id):
22 | data = Post.objects.get(id=id)
23 | if request.method == 'POST':
24 | form = CommentForm(request.POST)
25 | ids = request.POST.get('hidden')
26 | print("suman raj khanal")
27 | print(ids)
28 | if ids == "":
29 | if form.is_valid():
30 | name = form.cleaned_data['name']
31 | comments = form.cleaned_data['comments']
32 | dt = Comment(name=name,comments=comments,post = data)
33 | dt.save()
34 | return HttpResponseRedirect(f'/singlepost/{id}/')
35 | else:
36 | if form.is_valid():
37 | name = form.cleaned_data['name']
38 | comments = form.cleaned_data['comments']
39 | parent = Comment.objects.get(id=ids)
40 | dt = Comment(name=name,comments=comments,post = data,parent=parent)
41 | dt.save()
42 | return HttpResponseRedirect(f'/singlepost/{id}/')
43 |
44 | else:
45 | form = CommentForm()
46 | comment = Comment.objects.filter(post = data, parent=None)
47 | replies = Comment.objects.filter(post = data).exclude(parent=None)
48 | print('suman raj khanal')
49 | number = len(comment)
50 | print(replies)
51 | return render(request,'html/singlePost.html',{'data':data,'form':CommentForm,'comment':comment,'count':number,'reply':replies})
52 |
53 | # def comment(request):
54 | # return HttpResponseRedirect('//')
--------------------------------------------------------------------------------
/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/db.sqlite3
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'post.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/post/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/post/__init__.py
--------------------------------------------------------------------------------
/post/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/post/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/post/__pycache__/settings.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/post/__pycache__/settings.cpython-38.pyc
--------------------------------------------------------------------------------
/post/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/post/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/post/__pycache__/wsgi.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srksuman/Comment-system-in-Django/ede8a75d309160a08f26e8bcd0068300cc5d417e/post/__pycache__/wsgi.cpython-38.pyc
--------------------------------------------------------------------------------
/post/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for post project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'post.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/post/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for post project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.2.6.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.2/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 |
15 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
16 | BASE_DIR = Path(__file__).resolve().parent.parent
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = 'django-insecure-nrzretu&553)gs@@x7q1n5$&^pp0mbe+n7o6e4ib4mxc!47!w3'
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | 'django.contrib.admin',
35 | 'django.contrib.auth',
36 | 'django.contrib.contenttypes',
37 | 'django.contrib.sessions',
38 | 'django.contrib.messages',
39 | 'django.contrib.staticfiles',
40 | 'comment',
41 | 'ckeditor'
42 | ]
43 |
44 | MIDDLEWARE = [
45 | 'django.middleware.security.SecurityMiddleware',
46 | 'django.contrib.sessions.middleware.SessionMiddleware',
47 | 'django.middleware.common.CommonMiddleware',
48 | 'django.middleware.csrf.CsrfViewMiddleware',
49 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
50 | 'django.contrib.messages.middleware.MessageMiddleware',
51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
52 | ]
53 |
54 | ROOT_URLCONF = 'post.urls'
55 |
56 | TEMPLATES = [
57 | {
58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59 | 'DIRS': [],
60 | 'APP_DIRS': True,
61 | 'OPTIONS': {
62 | 'context_processors': [
63 | 'django.template.context_processors.debug',
64 | 'django.template.context_processors.request',
65 | 'django.contrib.auth.context_processors.auth',
66 | 'django.contrib.messages.context_processors.messages',
67 | ],
68 | },
69 | },
70 | ]
71 |
72 | WSGI_APPLICATION = 'post.wsgi.application'
73 |
74 |
75 | # Database
76 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
77 |
78 | DATABASES = {
79 | 'default': {
80 | 'ENGINE': 'django.db.backends.sqlite3',
81 | 'NAME': BASE_DIR / 'db.sqlite3',
82 | }
83 | }
84 |
85 |
86 | # Password validation
87 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
88 |
89 | AUTH_PASSWORD_VALIDATORS = [
90 | {
91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92 | },
93 | {
94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95 | },
96 | {
97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98 | },
99 | {
100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101 | },
102 | ]
103 |
104 |
105 | # Internationalization
106 | # https://docs.djangoproject.com/en/3.2/topics/i18n/
107 |
108 | LANGUAGE_CODE = 'en-us'
109 |
110 | TIME_ZONE = 'UTC'
111 |
112 | USE_I18N = True
113 |
114 | USE_L10N = True
115 |
116 | USE_TZ = True
117 |
118 |
119 | # Static files (CSS, JavaScript, Images)
120 | # https://docs.djangoproject.com/en/3.2/howto/static-files/
121 |
122 | STATIC_URL = '/static/'
123 |
124 | # Default primary key field type
125 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
126 |
127 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
128 |
129 | CKEDITOR_CONFIGS = {
130 | 'default': {
131 | 'toolbar': 'Full', #Basic
132 | 'height': 200,
133 | 'width': 1120,
134 | },
135 | }
--------------------------------------------------------------------------------
/post/urls.py:
--------------------------------------------------------------------------------
1 |
2 | from django.contrib import admin
3 | from django.urls import path
4 | from comment.views import homeFunction,allPostFunction,singlePost
5 |
6 | urlpatterns = [
7 | path('admin/', admin.site.urls),
8 | path('',homeFunction,name="home"),
9 | path('allpost/',allPostFunction,name="allpost"),
10 | path('singlepost//',singlePost,name="singlepost"),
11 | # path('comment/',comment,name="comment"),
12 |
13 |
14 |
15 | ]
16 |
--------------------------------------------------------------------------------
/post/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for post project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'post.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------