Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15461

Should I subclass my django model or not?

$
0
0

I'm creating a simple forum app in order to learn django. The idea is to create as much a full featured forum as I can over time, but for now this is what I have:

class Post(models.Model):    post_body = models.TextField(max_length=2000)    publish_date = models.DateTimeField("date posted")    author = models.TextField(max_length=200)  # link to User model later    class Meta:        abstract = True# Post that starts a threadclass ThreadPost(Post):    post_title = models.Charfield(200)    is_solved = models.BooleanField("is_issue_solved", default=False)class ReplyPost(Post):    is_solution = models.BooleanField("is_this_the_solution", default=False)    thread_post = models.ForeignKey(ThreadPost, on_delete=models.CASCADE)

I'm unsure if this this is overdoing it a bit. ThreadPost and ReplyPost are so similar. Should I instead just create two separate classes which are unrelated through inheritance?

Should I just have one Post class and just make the post_title optional when it's a reply? I guess the singular Post class would have to have a recursive relation too in that case (0 to N).

Also, in future I want to add other features like reactions (e.g. thumbs up/down, laugh etc.), ability to report a post etc. Which I think could be a seperate model that links Post and User and would have its own fields.

I wonder what approach would be best to keep the models flexible for future improvements.


Viewing all articles
Browse latest Browse all 15461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>