Problem/Gap
The Django CMS documentation clearly describes the process for extending the Page and Title Models. However, documentation on the possibility of adding a method such as the property method below is lacking, or I can't seem to find it.
Note: The example provided works perfectly when I include it directly under the Django CMS
Pagemodel. This is not the preferred way of course.
Question
Say I want to add the below method to the Page (cms.models.pagemodel.Page) or Title Model (assuming they are likely to follow the same process) outside the CMS app. How can this be achieved?
@property
def my_custom_page_property(self):
try:
logger.info(f'Working....')
return {}
except Exception as e:
logger.error(f'Error: {e}')
return {}
Attempt
In a seperate app I added the code below, and migrated. The image field is properly configured and works fine. The method however doesn't seem to return anything.
from cms.extensions import PageExtension
from cms.extensions.extension_pool import extension_pool
class MyCustomExtension(PageExtension):
image = models.ForeignKey(Image,
on_delete=models.SET_DEFAULT,
default=None,
blank=True,
null=True)
@property
def my_custom_page_property(self):
..
This is possible - I've set it up with a page extension I use for adding images to pages.
So taking the example;
Then in the template I've got;
This
test_propis being rendered to the page.