Search code examples
pythondjangotwitter-bootstrapdjango-cms

Django CMS - DIVIO LogEntry add instance / Latest files added to the CMS


I need to show at my Homepage a list with all the files added/changed as Bootstrap Filer plugin to my Django CMS project. I was using the LogEntry model, but it doesn't save Add actions to LogEntry instances. What I need is something like that:

Latest Changes:

  • May 30, 2017 - Test.pdf
  • May 28, 2017 - Application Form.pdf
  • May 26, 2017 - Brooker.pdf

My problem is that the Add's actions are not saved at LogEntry model... Every time I add, for example, Bootstrap Filer Plugin and add a PDF it doesn't save a new Entry instance of it, only when I delete it. How do I change the default behavior to save Plugin's Add Actions (specially Bootstrap Filer File) at LogEntry Models?

The website is a platform to help insurance brokers to sell. The prices of different companies changes on monthly basis. And every time a new Price table change I need to show in a Latest changes / updates section.

My models.py

poll = list(LogEntry.objects.all())

    def __unicode__(self):
        return unicode(self.poll)

My template:

    <ul>
    {% for poll in instance.poll %}
      {% if poll.content_type_id == 54 %} <!-- Bootstrap Files Plugin Content Type -->
        <li>
          {{poll.action_time.date }} - {{ poll.object_repr }} - {{ poll.object_repr }}
        </li>
      {% endif %}
    {% endfor %}
   </ul>

What's the best way to do that?


Solution

  • If the Bootstrap3FilePlugin model suits your needs but you'd like to change its behaviour, the best thing to do is to subclass it.

    It will be something like this:

    • Create a module of your own containing the new code.

    • Subclass the plugin model

      from aldryn_bootstrap3.models import Bootstrap3FilePlugin
      
          class MyNewBootstrap3FilePlugin(Bootstrap3FilePlugin):
          ...
      
    • Add a new field, for example:

      last_updated = models.DateTimeField(auto_now_add=True)
      

      See the DateTimeField/DateField reference.

    • You will also need to subclass the Bootstrap3FileCMSPlugin plugin class to point at a new template:

      render_template = <whatever>
      

      that will display the new last_updated field.