Hi all,
As a learning project I’m trying to create a disscussion forum. Over time I want to recreate a typical forum where users can create threads, reply to threads, reply to replies, react, report etc.
But for now this is where I’m at:
class Post(models.Model):
post_body = models.TextField(max_length=2000)
publish_date = models.DateTimeField("date posted")
author = models.TextField(max_length=200) # placeholder, link to users table later
class Meta:
abstract = True
# Post that starts a thread
class ThreadPost(Post):
post_title = models.Charfield(200)
is_solved = models.BooleanField("is_issue_solved")
# reply to a specific thread
class ReplyPost(Post):
is_solution = models.BooleanField("is_this_the_solution")
thread_post = models.ForeignKey(ThreadPost, on_delete=models.CASCADE)
The ThreadPost
and ReplyPost
are so similar. I wonder if I should just have a single non-abstract Post
class with an optional post_title
field. Just make it so that when a user clicks “create thread”, the title is not optional.
And since in future I’ll want users to be able to reply to replies, the thread_post = models.ForeignKey(ThreadPost, ...)
line could probably just refer to antoher Post
instance anyway.
Maybe I could move is_solved
out to a seperate model too, which refers to the thread that solved, when it was marked solved, and which (if any) reply was the solution.