This repository was archived by the owner on Jun 7, 2020. It is now read-only.
File tree 4 files changed +42
-5
lines changed
4 files changed +42
-5
lines changed Original file line number Diff line number Diff line change
1
+ {% extends 'wall/base.html' %}
2
+
3
+ {% block content %}
4
+
5
+ < h1 > Edit comment</ h1 >
6
+
7
+ < form method ="POST " class ="post-form ">
8
+ {% csrf_token %}
9
+ {{ form.as_p }}
10
+ < button type ="submit " class ="save btn btn-default "> Edit Comment</ button >
11
+ </ form >
12
+
13
+ {% endblock %}
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ <h2>{{ post.title }}</h2>
14
14
< h3 > {{ comment.title }}</ h3 >
15
15
< p class ='text '> {{ comment.text }}</ p >
16
16
< p class ='fotter '> < span class ='date '> {{ comment.created_date }}</ span > </ p >
17
+ < a href ="{% url 'comment_edit' comment.pk %} "> Edit comment</ a >
17
18
</ div >
18
19
{% endfor %}
19
20
< a href ={% url 'comment_new' post_pk=post.pk %} > Add a comment</ a >
Original file line number Diff line number Diff line change 11
11
views .comment_write_new ,
12
12
name = 'comment_new'
13
13
),
14
+ url (
15
+ r'^comment/(?P<pk>[0-9]+)/$' ,
16
+ views .comment_edit ,
17
+ name = 'comment_edit'
18
+ ),
14
19
)
Original file line number Diff line number Diff line change 1
- from django .shortcuts import render
2
- from django .shortcuts import redirect
3
-
1
+ from django .shortcuts import render , redirect , get_object_or_404
4
2
from .forms import PostForm , CommentForm
5
- from .models import Post
3
+ from .models import Post , Comment
6
4
7
5
8
6
def example_html_view (request ):
@@ -60,7 +58,7 @@ def comment_write_new(request, post_pk):
60
58
comment .save ()
61
59
return redirect ('post_detail' , pk = post_pk )
62
60
else :
63
- form = PostForm ()
61
+ form = CommentForm ()
64
62
65
63
return render (
66
64
request ,
@@ -69,3 +67,23 @@ def comment_write_new(request, post_pk):
69
67
'post_pk' : post_pk ,
70
68
}
71
69
)
70
+
71
+
72
+ def comment_edit (request , pk ):
73
+
74
+ obj = get_object_or_404 (Comment , pk = pk )
75
+
76
+ if request .method == "POST" :
77
+ form = CommentForm (request .POST , instance = obj )
78
+ if form .is_valid ():
79
+ form .save ()
80
+ return redirect ('post_detail' , pk = obj .post .pk )
81
+ else :
82
+ form = CommentForm (instance = obj )
83
+
84
+ return render (
85
+ request ,
86
+ 'wall/comment_edit.html' , {
87
+ 'form' : form ,
88
+ }
89
+ )
You can’t perform that action at this time.
0 commit comments