Commit 6ccf5db8 authored by Ron Rodillas's avatar Ron Rodillas

Created the edit post page

parent 5df3ae23
No preview for this file type
# Generated by Django 4.1.7 on 2023-05-13 16:10
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0006_forumpost_replies'),
]
operations = [
migrations.RemoveField(
model_name='forumpost',
name='replies',
),
migrations.AlterField(
model_name='reply',
name='forum_post',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='post_replies', to='forum.forumpost'),
),
]
...@@ -7,7 +7,7 @@ class ForumPost (models.Model): ...@@ -7,7 +7,7 @@ class ForumPost (models.Model):
body = models.TextField() body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True) author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True) pub_datetime = models.DateTimeField(auto_now_add=True)
replies = models.ManyToManyField('self', blank=True)
def __str__(self): def __str__(self):
return self.title return self.title
...@@ -18,6 +18,9 @@ class ForumPost (models.Model): ...@@ -18,6 +18,9 @@ class ForumPost (models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('forum:PostDetailView', kwargs={'pk': self.pk}) return reverse('forum:PostDetailView', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('forum:PostUpdateView', kwargs={'pk': self.pk})
class Reply (models.Model): class Reply (models.Model):
body = models.TextField() body = models.TextField()
......
...@@ -28,5 +28,5 @@ by {{reply.author.first_name}} {{reply.author.last_name}} <br> ...@@ -28,5 +28,5 @@ by {{reply.author.first_name}} {{reply.author.last_name}} <br>
{% endfor %} {% endfor %}
</p2> </p2>
<br> <br>
<button>Edit Post</button> <a href = "{{object.get_update_url}}"><button>Edit Post</button></a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,10 +2,16 @@ ...@@ -2,10 +2,16 @@
{% load static %} {% load static %}
{% block title %} {% block title %}
Edit Post
{% endblock %} {% endblock %}
{% block styles %} {% block styles %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h1>Edit Post</h1><br>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Post">
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -5,6 +5,7 @@ urlpatterns = [ ...@@ -5,6 +5,7 @@ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('forumposts/add/', PostCreateView.as_view(), name='addPost'), path('forumposts/add/', PostCreateView.as_view(), name='addPost'),
path('forumposts/<int:pk>/details', PostDetailView.as_view(), name='PostDetailView'), path('forumposts/<int:pk>/details', PostDetailView.as_view(), name='PostDetailView'),
path('forumposts/<int:pk>/edit', PostUpdateView.as_view(), name='PostUpdateView'),
] ]
app_name="forum" app_name="forum"
\ No newline at end of file
...@@ -14,6 +14,11 @@ class PostCreateView(CreateView): ...@@ -14,6 +14,11 @@ class PostCreateView(CreateView):
fields = '__all__' fields = '__all__'
template_name = 'forum/forumpost-add.html' template_name = 'forum/forumpost-add.html'
class PostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
class PostDetailView(DetailView): class PostDetailView(DetailView):
model = ForumPost model = ForumPost
template_name = 'forum/forumpost-details.html' template_name = 'forum/forumpost-details.html'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment