0

我的任务是获取文章列表。本文来自一个简单的 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,})

我想在不同的子页面中使用它。

现在在主页上获得所有文章的列表会很棒(我的项目 -> project1、project2、project3 的列表)。

类似于: Article.objects.all() 模板:

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

但我得到一个错误“类型对象'Articles'没有属性'对象'......你有一个聪明的想法吗?使用Feincms ContentType会很好。

4

1 回答 1

0

FeinCMS 内容类型是抽象的,这意味着没有数据和与之关联的数据库表。因此,没有objects经理,也没有办法查询。

这样做时Page.create_content_type(),FeinCMS 获取内容类型和相应的Page类,并创建一个包含实际数据的(非抽象)模型。为了访问这个新的具体模型,您需要使用content_type_for. 换句话说,您正在寻找:

from feincms.module.page.models import Page
PageArticle = Page.content_type_for(Article)
articles = PageArticle.objects.all()
于 2015-10-17T18:09:13.437 回答