ellmetha / django-machina

A Django forum engine for building powerful community driven websites.
https://django-machina.readthedocs.org
BSD 3-Clause "New" or "Revised" License
589 stars 126 forks source link

factor out create_post and create_topic #275

Closed BoPeng closed 2 years ago

BoPeng commented 2 years ago

This PR is purely for the convenience of extending PostForm and TopicForm. In my application, I create separate Post and Topic models for user comment so that they are saved in separate databases. I derive my own

class CommentPostForm(PostForm)

but I have to

  1. Copy the implementation of PostForm.save() and TopicForm.save() to replace Post() and Topic() with my own classes, and
  2. Call super(PostForm, self).save() instead of super().save()becausePostFormwill create aPost` object.

By factoring out create_post, update_post, create_topic, and update_topic from the save() functions, I can just override the corresponding functions.

Note that for CommentTopic to make use of Topic.save() while deriving from CommentPost, I will need to do

class CommentPost(Post):
    ...

class CommentTopic(Topic, CommentPost)
    ...