Django cms accessing extended property

落爺英雄遲暮 提交于 2019-12-08 05:13:27
request.current_page.extended_fields.page_image

should work if you are using < 2.4. In 2.4 they introduced a new two page system (published/draft) so you might need

request.current_page.publisher_draft.extended_fields.page_image

I usually write some middleware or a template processor to handle this instead of doing it repetitively in the template. Something like:

class PageOptions(object):
    def process_request(self, request):
        request.options = dict()
        if not request.options and request.current_page:
            extended_fields = None
            try:
                extended_fields = request.current_page.extended_fields
            except:
                try:
                    custom_settings = request.current_page.publisher_draft.extended_fields
                except:
                    pass
            if extended_fields:
                for field in extended_fields._meta.fields:
                    request.options[field.name] = getattr(extended_fields, field.name)
        return None

will allow you to simply do {{ request.options.page_image }}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!