diff --git a/db.sqlite3 b/db.sqlite3 index 1d9712b..99243fe 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/news/__pycache__/models.cpython-37.pyc b/news/__pycache__/models.cpython-37.pyc index 19840d3..32131a7 100644 Binary files a/news/__pycache__/models.cpython-37.pyc and b/news/__pycache__/models.cpython-37.pyc differ diff --git a/news/__pycache__/urls.cpython-37.pyc b/news/__pycache__/urls.cpython-37.pyc index 5adae1e..51a5583 100644 Binary files a/news/__pycache__/urls.cpython-37.pyc and b/news/__pycache__/urls.cpython-37.pyc differ diff --git a/news/__pycache__/views.cpython-37.pyc b/news/__pycache__/views.cpython-37.pyc index 5092237..568bcc1 100644 Binary files a/news/__pycache__/views.cpython-37.pyc and b/news/__pycache__/views.cpython-37.pyc differ 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 b26093f..012c39e 100644 Binary files a/news/migrations/__pycache__/0001_initial.cpython-37.pyc and b/news/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/news/migrations/__pycache__/__init__.cpython-37.pyc b/news/migrations/__pycache__/__init__.cpython-37.pyc index d16688b..d19198b 100644 Binary files a/news/migrations/__pycache__/__init__.cpython-37.pyc and b/news/migrations/__pycache__/__init__.cpython-37.pyc differ 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

+

+ +

+ + +
+ 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,)))