Search code examples
djangodjango-modelsdjango-admindjango-cms

Better way to connect django model with django cms page/placeholder


I'm making a website, and one of the features - News. I have a model News with some fields, to have a better user experience i thought that i need some more information for every News - html snippet and for good administrating that additional content for News, i decided that i need to use django csm. So on every page i have an information from News model and in the end of that - html snippet made with cms. And there is a problem - i don't know the better way to make my wishes.

Important bit: i want to make all connections with model slug.

  1. I read docs about apphooks - but maybe it's not a good approach in my case? Couse apphooks make application embedding to django cms, but i need only the piece of creation and connecting of html template made by this cms.

  2. Additionally i tried just take a Page made by cms and put it in my html, but it was something wrong there, maybe it is not possible? Maybe i can see pages only on cms urls?

page = Page.objects.all()[0] # for example in views

  1. I tried to make the model placeholder, but again it was something wrong here, and i didn't see anything on default application page. placeholders = PlaceholderRelationField() @cached_property def my_placeholder(self): return get_placeholder_from_slot(self.placeholders, "slot_name")

Solution

  • I am not sure if I fully understand the issue. My understanding of the question was: How can I add HTML content to a news item?

    A simple solution to your problem might be to add a HTMLField to your news model. It comes from djangocms_text_ckeditor.fields and essentially allows to enter HTML rich text.

    If that is the only use for django CMS, you might just take any rich text field with a suitable HTML editor for the django admin.