feat: added foreign key Post to Reply model, associating a reply to a specific post

parent 272241dd
# Generated by Django 4.0.3 on 2022-04-05 08:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0002_post_author_reply'),
]
operations = [
migrations.AddField(
model_name='reply',
name='associated_post',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='post', to='forum.post'),
),
]
...@@ -8,7 +8,14 @@ class Post(models.Model): ...@@ -8,7 +8,14 @@ class Post(models.Model):
post_body = models.CharField(max_length=1000) post_body = models.CharField(max_length=1000)
pub_date = models.DateTimeField("Date published") pub_date = models.DateTimeField("Date published")
def __str__(self):
return self.post_title
class Reply(models.Model): class Reply(models.Model):
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True)
associated_post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True, related_name='post')
reply_body = models.CharField(max_length=1000) reply_body = models.CharField(max_length=1000)
pub_date = models.DateTimeField("Replied on") pub_date = models.DateTimeField("Replied on")
def __str__(self):
return self.reply_body
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