nitely / Spirit

Spirit is a modern Python based forum built on top of Django framework
http://spirit.readthedocs.io
MIT License
1.16k stars 334 forks source link

Method to add fields to Topic or Comment #300

Open BoPeng opened 3 years ago

BoPeng commented 3 years ago

What is the recommended method to add extra fields like tags from django-taggit to Spirit models such as Topic or Comment?

BoPeng commented 3 years ago

https://github.com/nitely/Spirit/issues/96#issuecomment-175468844 seems to be closest existing discussion that I can find.

BoPeng commented 3 years ago

Spirit does not aim to have overridable apps, you should be able to extend it

So spirit did not allow adding additional fields to the Topic class, like what django-oscar and django-machina provide. Is this still the case now?

nitely commented 3 years ago

Create an app, add a model with a OneToOne field to Topic, and the extra fields you need, fork Spirit and add the form to the relevant views and templates.

Extending the Spirit model in-place (like just adding fields willy nilly) is not a good idea. It'll create conflicts with future migrations.

What django-oscar and django-machina provide is not a plugin system; they let you extend/override some model or form, but their way is not composable. How do multiple apps/plugin extend the same model?.

BoPeng commented 3 years ago

Say there is a "product" in my website that a Topic needs to promote. What you are suggesting is that

  1. I create a TopicThatRecommendsProduct model that is one to one to Topic, which is ok.
  2. Since the sprit renderer does not know Product, I will need to fork spirit to add views and forms to mention product, so the fork will actually import product from my models.

Compared to the django-oscar approach, I think the biggest problem is that I will have to maintain Product in both my website and the spirit fork. Can django-hook be used to avoid a fork?

nitely commented 3 years ago

Step 2 is to create a form for your product model. Step 3 is to fork Spirit and add the form to whatever view and templates are needed to display the form. You'll need to maintain (i.e: solve git conflicts) the affected views and templates.

Can django-hook be used to avoid a fork?

Yes, but it was never integrated into Spirit, so no...