From 908ae1a139a8fa6d9cb332cf38f06f40bed91ed1 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 10 Sep 2019 16:28:17 +0200 Subject: [PATCH] added ability to add comments --- db.sqlite3 | Bin 176128 -> 176128 bytes news/__pycache__/models.cpython-37.pyc | Bin 2193 -> 2193 bytes news/__pycache__/urls.cpython-37.pyc | Bin 417 -> 470 bytes news/__pycache__/views.cpython-37.pyc | Bin 1611 -> 1910 bytes news/migrations/0001_initial.py | 2 +- .../__pycache__/0001_initial.cpython-37.pyc | Bin 1496 -> 1496 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 141 -> 141 bytes news/templates/news/index.html | 2 +- news/templates/news/post.html | 14 ++++++++++++- news/templates/news/submission.html | 19 +++++++++++------- news/urls.py | 1 + news/views.py | 11 ++++++++-- 12 files changed, 37 insertions(+), 12 deletions(-) diff --git a/db.sqlite3 b/db.sqlite3 index 1d9712bc7687835c50f61a3df67e2fd7378aa6aa..99243fe2fe531616dc0ee221af433b6959b03a7d 100644 GIT binary patch delta 1287 zcmah|OKcle6rGPPc`TeqK~*SmYDY~`(yGq;&3iM33OSv`2~up4*fI8ol-P;CW8*P( z;suSm=z@<_^du^=pk>E`MIllaY${er-5?~C4Vy?^5QGp?CDa8V@nVQwwWvrlXL0U% z_ue`0%+5h@=OB1vOr8EHd`X@Dat)4+&^WT=h{sIA5yRrsu`@#obIh6eZj25n$}NP6 zI1%PUiZNnCu^N7PNKp$zB5sA_LyBN-BJorB)ggsAA*P_?=71tL#T<$5I13%`MQp^l z`1(;1GcmTsU*p3a2%!W*F?;%zVJk$bX^IaXp|EX1#>D>VivtyAkWwZlBIb+712M&r zno##Eqh}MBi;apaK8w6CJRyrF6CX#0J|P<+h{U&%^DiAYLCmDs3W3j+09aGN&)^5p z26w?H;C*lhtnE%j7r^MVKtHRxrLOnpdb80exgGzgUni>g=9%ZkdoxtkcJI#2!GH#? zE8s_PefLDG2TrYMhB9$-F=3oEHY#ne6KyrUj@xug;@##sP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8>PhaADxlh5G|uQ(h_n diff --git a/news/migrations/0001_initial.py b/news/migrations/0001_initial.py index f6cd385..0ce5620 100644 --- a/news/migrations/0001_initial.py +++ b/news/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.5 on 2019-09-10 10:05 +# Generated by Django 2.2.5 on 2019-09-10 14:19 from django.conf import settings from django.db import migrations, models diff --git a/news/migrations/__pycache__/0001_initial.cpython-37.pyc b/news/migrations/__pycache__/0001_initial.cpython-37.pyc index b26093f9c323bb45c04d6925e7298a517d89a05b..012c39e60ade3fddc9a98291ba1e7d7ae5cfd7ed 100644 GIT binary patch delta 19 Zcmcb?eS@3JiI}BL~;^pOH0D@Z^CUP|c03odeH2?qr delta 18 XcmeBW>}BL~;^pOH0D_FtiCoP99)|;n diff --git a/news/templates/news/index.html b/news/templates/news/index.html index b2257a7..186e4bd 100644 --- a/news/templates/news/index.html +++ b/news/templates/news/index.html @@ -3,7 +3,7 @@ {% if latest_post_list %} {% else %} diff --git a/news/templates/news/post.html b/news/templates/news/post.html index 6c83520..059d777 100644 --- a/news/templates/news/post.html +++ b/news/templates/news/post.html @@ -3,8 +3,20 @@

----Body----

{{ post.content }}

----Comments----

+ +
+ {% csrf_token %} + +

Add comment

+

+ +

+ + +
+
    {% for comment in post.comment_set.all %} -
  • {{ comment.content }}
  • +
  • {{ comment.body }}
  • {% endfor %}
diff --git a/news/templates/news/submission.html b/news/templates/news/submission.html index 7ae033c..0bd8b37 100644 --- a/news/templates/news/submission.html +++ b/news/templates/news/submission.html @@ -2,24 +2,29 @@ {% if user.is_authenticated %} + +

Submit some amazing content!

+
{% csrf_token %}

Title> - +

+

- Image URL> - + URL> +

+

- Content> - + Body> +

- URL> - + Image URL> +

diff --git a/news/urls.py b/news/urls.py index 35660d7..487c1e7 100644 --- a/news/urls.py +++ b/news/urls.py @@ -8,6 +8,7 @@ urlpatterns = [ path('', views.post, name='post'), path('submission', views.submission, name='submission'), path('submit', views.submit, name='submit'), + path('/comment', views.comment, name='comment'), path('submitted', views.submitted, name='submitted'), ] diff --git a/news/views.py b/news/views.py index b46ea5b..6ffd660 100644 --- a/news/views.py +++ b/news/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render, get_object_or_404 from django.http import HttpResponse, Http404, HttpResponseRedirect from django.template import loader from django.urls import reverse -from .models import Post +from .models import Post, Comment from datetime import datetime import logging @@ -25,7 +25,7 @@ def submit(request): if 'state' in request.POST: post = Post.objects.create(author=request.user,date=datetime.today()) post.title = request.POST['title'] - post.content = request.POST['content'] + post.body = request.POST['body'] post.url = request.POST['url'] post.image_url = request.POST['image_url'] post.state = request.POST['state'] @@ -37,3 +37,10 @@ def submit(request): def submitted(request): return render(request, 'news/submitted.html', {}) + +def comment(request, post_id): + comment = Comment(author=request.user,date=datetime.today()) + comment.post = get_object_or_404(Post, pk=post_id) + comment.body = request.POST['body'] + comment.save() + return HttpResponseRedirect(reverse('news:post', args=(post_id,)))