Upgrade to Pro — share decks privately, control downloads, hide ads and more …

First steps with django CMS

First steps with django CMS

Basic django CMS introduction given at PyCon UK 2014

Iacopo Spalletti

September 21, 2014
Tweet

More Decks by Iacopo Spalletti

Other Decks in Programming

Transcript

  1. WHO AM I? Founder and Lead developer @NephilaIt django CMS

    core developer django CMS installer author
  2. DJANGO CMS FIRST LOOK BRIEF OVERVIEW OF DJANGO CMS FEATURES

    FEEL FREE TO COME TO THE BOOTH OR AT THE SPRINTS FOR MORE
  3. LIVES IN A LIVE AND DRAFT VERSION DEFINED BY THE

    TEMPLATE APPLIED TO IT PAGE THE BUILDING BLOCK OF THE CMS
  4. PLACEHOLDER THERE IS MORE class MyModel(models.Model): name = models.CharField(max_length=200) abstract

    = models.TextField() content = PlaceholderField() Composition, not inheritance
  5. PLUGIN WRITING PLUGIN IS EASY class MyPlugin(CMSPluginBase): name = _('My

    plugin') render_template = 'myapp/myplugin.html'
  6. PLUGIN 1. PLUGIN CLASS class MyPlugin(CMSPluginBase): name = _('My plugin')

    model = MyPluginModel render_template = 'myapp/myplugin.html' def render(self, context, instance, placeholder): newslist = News.objects.all().order_by('-date') context.update({ 'instance': instance, 'news_list': newslist[:instance.posts] }) return context Plugin = ModelAdmin + template + get_context_data
  7. PLUGIN 2. THE PLUGIN MODEL It's the plugin configuration class

    MyPluginModel(CMSPlugin): title = models.CharField(max_length=200) posts = models.PositiveIntegerField()
  8. PLUGIN 3. THE TEMPLATE Template is a standard Django template

    fragment to which the plugin generated context is provided <div class="news_list"> <h2>{{ instance.title }}</h2> {% for news in news_list %} <a href="{{ news.get_absolute_url }}"> {{ news.title }}</a><br> {% endfor %} </div>
  9. APPHOOK Is a bridge between the CMS and other Django

    applications In rough terms, it appends the application URLConf to the page tree
  10. It wraps the URLCon in a class APPHOOK SOME CODE

    class MyApp(CMSApp): name = _("My App") urls = ["apps.my_app.urls"] menus = [MyMenu] apphook_pool.register(MyApp)
  11. FRONTEND EDITOR ANCHE NEI VOSTRI MODEL EVERY MODEL CAN BE

    FRONTEND-ENABLED {% render_model instance "abstract" %} {% render_model_block instance %} <h3>{{ instance.title }}</h3> <div class="date">{{ instance.date }}</div> {% endrender_model_block %}
  12. GRAZIE! SEE YOU TOMORROW! DJANGO CMS SPRINT And tips and

    support to use django CMS Iacopo Spalletti [email protected] @yakkys