added ability to add comments

master
Laurent 6 years ago
parent 1514224b66
commit 908ae1a139
  1. BIN
      db.sqlite3
  2. BIN
      news/__pycache__/models.cpython-37.pyc
  3. BIN
      news/__pycache__/urls.cpython-37.pyc
  4. BIN
      news/__pycache__/views.cpython-37.pyc
  5. 2
      news/migrations/0001_initial.py
  6. BIN
      news/migrations/__pycache__/0001_initial.cpython-37.pyc
  7. BIN
      news/migrations/__pycache__/__init__.cpython-37.pyc
  8. 2
      news/templates/news/index.html
  9. 14
      news/templates/news/post.html
  10. 19
      news/templates/news/submission.html
  11. 1
      news/urls.py
  12. 11
      news/views.py

Binary file not shown.

@ -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

@ -3,7 +3,7 @@
{% if latest_post_list %}
<ul>
{% for post in latest_post_list %}
<li><a href="{% url 'news:post' post.id %}">{{ post.title }}</a></li>
<li><a href="{{ post.url }}">{{ post.title }}</a> - <a href="{% url 'news:post' post.id %}">comments</a></li>
{% endfor %}
</ul>
{% else %}

@ -3,8 +3,20 @@
<p>----Body----</p>
<p>{{ post.content }}</p>
<p>----Comments----</p>
<form action="{% url 'news:comment' post.id %}" method="post">
{% csrf_token %}
<p>Add comment</p>
<p>
<textarea name="body" rows="8" cols="80"></textarea>
</p>
<input type="submit" value="Submit">
</form>
<ul>
{% for comment in post.comment_set.all %}
<li>{{ comment.content }}</li>
<li>{{ comment.body }}</li>
{% endfor %}
</ul>

@ -2,24 +2,29 @@
{% if user.is_authenticated %}
<h1>Submit some amazing content!</h1>
<form action="{% url 'news:submit' %}" method="post">
{% csrf_token %}
<p>
<span>Title</span>>
<input type="text" name="title" maxlength="200" required id="id_title">
<input type="text" name="title" maxlength="200" required id="id_title" size="100">
</p>
<p>
<span>Image URL</span>>
<input type="text" name="image_url" maxlength="200" required id="id_image_url">
<span>URL</span>>
<input type="text" name="url" maxlength="200" required id="id_url" size="100">
</p>
<p>
<span>Content</span>>
<input type="text" name="content" maxlength="10000" required id="id_content">
<span>Body</span>>
<input type="text" name="body" maxlength="10000" required id="id_body" size="100">
</p>
<p>
<span>URL</span>>
<input type="text" name="url" maxlength="200" required id="id_url">
<span>Image URL</span>>
<input type="text" name="image_url" maxlength="200" required id="id_image_url" size="100">
</p>
<p>

@ -8,6 +8,7 @@ urlpatterns = [
path('<int:post_id>', views.post, name='post'),
path('submission', views.submission, name='submission'),
path('submit', views.submit, name='submit'),
path('<int:post_id>/comment', views.comment, name='comment'),
path('submitted', views.submitted, name='submitted'),
]

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

Loading…
Cancel
Save