diff --git a/projboard/templates/editArticle/edit_article.html b/projboard/templates/editArticle/edit_article.html
index e25b854..8968e05 100644
--- a/projboard/templates/editArticle/edit_article.html
+++ b/projboard/templates/editArticle/edit_article.html
@@ -11,12 +11,11 @@
Smarticle
-
-
-
Edit Article
-
-
-
+
+
Edit Article
+
+
+{% endblock %}
diff --git a/projboard/views.py b/projboard/views.py
index f11791b..39cd816 100644
--- a/projboard/views.py
+++ b/projboard/views.py
@@ -122,33 +122,36 @@ def sign_up(request):
def delete_article(request, article_pk):
try:
article = Article.objects.get(id=article_pk)
+ user = article.user_id
article.delete()
- return redirect(home_page)
+ nickname = user.nickname
+ return redirect(f"/my_articles/{nickname}/")
- except User.DoesNotExist:
+ except Article.DoesNotExist:
raise Http404()
-def edit_article(request, article_pk):
+def edit_article(request, article_pk=None):
try:
- article = Article.objects.get(article_pk)
-
- initial = {'article_id': article, 'title': article.title,
- 'subject': article.subject_id, 'content': article.content}
+ article = Article.objects.get(id=article_pk)
+ user_id = article.user_id
+ title = article.title
+ subject_id = article.subject_id
+ content = article.content
+ initial = {'user_id': user_id, 'title': title, 'subject_id': subject_id, 'content': content}
if request.method == "POST":
- form = EditArticleForm(request.POST, initial=initial)
+ form = EditArticleForm(request.POST, initial)
if form.is_valid():
- form.save()
- return render(request, 'editArticle/edit_article.html', initial)
- # elif request.method == "DELETE":
- # raise Http404()
+ article.edit(form.data['title'], form.data['content'], form.cleaned_data['subject_id'])
+ return redirect(f"/my_articles/{user_id.nickname}/")
+ elif request.method == "DELETE":
+ raise Http404()
else:
form = EditArticleForm(initial=initial)
return render(request, 'editArticle/edit_article.html', {
- 'article_pk': article_pk,
+ 'user_id': user_id,
'form': form,
})
- except User.DoesNotExist:
- # raise Http404()
- return redirect(home_page)
+ except Article.DoesNotExist:
+ raise Http404()