Latest Articles
{% for article in articles %}
{{ article.body|truncatewords:30 }}
Read more
{% empty %}
No articles yet.
{% endfor %}
Create ``my_content/templates/my_content/article_list.html``:
.. code-block:: django
{{ article.title }}
Published on {{ article.id }}
{{ article.body|safe }}
{% cms_edit_off %}
{% endblock %}
Step 3: Enable App Hook
-----------------------
To enable URL routing for articles, add ``apphook = True`` to ``ArticleContent.CMSConfig``:
Update ``my_content/models.py``:
.. code-block:: python
class ArticleContent(AbstractCustomContent):
"""The editable article content."""
article = models.ForeignKey(Article, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
slug = models.SlugField()
body = models.TextField()
class CMSConfig:
# Make editable in frontend and versionable
editable = True
versionable = True
# Enable URL routing via app hook
apphook = True
def __str__(self):
return self.title
That's all you need! The generic detail view will automatically handle URL routing.
Step 4: Add the App Hook to a CMS Page
---------------------------------------
In the Django CMS admin:
1. Create a new Django CMS page (or edit an existing one)
2. Go to the **Advanced** tab
3. Under **Application**, select your app hook ("My Content")
4. Save the page
The generic detail view automatically handles displaying articles by slug.
Done!
-----
Your article model now has:
✅ CMS plugins for teaser and list display
✅ An app hook for frontend URLs
✅ Proper templates
✅ Frontend display of articles
Next Steps:
- :doc:`model_with_m2m` - Add authors to articles using M2M relations
- :doc:`../how-to/m2m_relations` - Learn more about generic M2M relations
- :doc:`../explanation/architecture` - Understand the grouper/content pattern