Question

I'm searching for a flexible way to reference one cmsplugin from another cmsplugin in order to allow the user to create links between them.

This must be a very common problem, so there should be a standard solution. But I cannot find it.

My current idea is to add a field to the model of my cmsplugin that is (in my case) a ManyToManyField pointing to something like CMSPluginBase. Then one has to set the option limit_choices_to and render the form in a way that the choices are displayed in a human readable way. But I want to avoid reinventing the wheel.

Était-ce utile?

La solution

I solved my problem by using the title field as unique identifiert of my CMSPlugin objects. When looking for related objects, I first take their titles, and then perform a query that collects all objects with the correct title and language that are published. Surely, this is not a nice solution.

There is a standard way to deal with relations in CMSPlugin models. One should define a copy_related method, as explained here. But this solution did not relaiably work for me when the relationships pointed to another CMSPlugin. This is due to the mechanism how draft pages are turned into published pages.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top