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):
body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
replies = models.ManyToManyField('self', blank=True)
def __str__(self):
return self.title
......@@ -18,6 +18,9 @@ class ForumPost (models.Model):
def get_absolute_url(self):
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):
body = models.TextField()
......
......@@ -28,5 +28,5 @@ by {{reply.author.first_name}} {{reply.author.last_name}} <br>
{% endfor %}
</p2>
<br>
<button>Edit Post</button>
<a href = "{{object.get_update_url}}"><button>Edit Post</button></a>
{% endblock %}
\ No newline at end of file
......@@ -2,10 +2,16 @@
{% load static %}
{% block title %}
Edit Post
{% endblock %}
{% block styles %}
{% endblock %}
{% 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 %}
\ No newline at end of file
......@@ -5,6 +5,7 @@ urlpatterns = [
path('', index, name='index'),
path('forumposts/add/', PostCreateView.as_view(), name='addPost'),
path('forumposts/<int:pk>/details', PostDetailView.as_view(), name='PostDetailView'),
path('forumposts/<int:pk>/edit', PostUpdateView.as_view(), name='PostUpdateView'),
]
app_name="forum"
\ No newline at end of file
......@@ -13,9 +13,14 @@ class PostCreateView(CreateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class PostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
class PostDetailView(DetailView):
model = ForumPost
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