Search code examples
djangotemplatesfeincms

List of Articles form FeinCMS Content Typs


my mission is to get a list of articles. This article come form a simple FeinCMS ContentType.

class Article(models.Model):
       image = models.ForeignKey(MediaFile, blank=True, null=True, help_text=_('Image'), related_name='+',)
       content = models.TextField(blank=True, help_text=_('HTML Content'))
       style = models.CharField(
                    _('template'),max_length=10, choices=(
                            ('default', _('col-sm-7 Image left and col-sm-5 Content ')),
                            ('fiftyfifty', _('50 Image left and 50 Content ')),
                            ('around', _('small Image left and Content around')),
                            ),
                            default='default')
        class Meta:
                abstract = True
                verbose_name = u'Article'
                verbose_name_plural = u'Articles'

        def render(self, **kwargs):
                return render_to_string('content/articles/%s.html' % self.style,{'content': self,})

I would like to use that in different subpages.

Now it would be great to get a list of all articels on the main page (my projects -> list of project1, project2, project3, ).

Something like: Article.objects.all() Template:

{% for entry in article %}
    {% if content.parent_id == entry.parent_id %} #only projects
        <p>{{ entry.content|truncatechars:180 }}</p>
    {% endif %}
{% endfor %}  

but i get a error "type object 'Articels' has no attribute 'objects'... Do you have a smart idea? It would be grade to use Feincms ContentType.


Solution

  • FeinCMS content types are abstract, that means there is no data and no database table associated with them. Therefore, there's no objects manager and no way to query.

    When doing Page.create_content_type(), FeinCMS takes the content type and the corresponding Page class and creates a (non-abstract) model which contains the actual data. In order to access that new, concrete model, you need to use content_type_for. In other words, you're looking for:

    from feincms.module.page.models import Page
    PageArticle = Page.content_type_for(Article)
    articles = PageArticle.objects.all()