【发布时间】:2015-10-16 18:20:58
【问题描述】:
我的任务是获取文章列表。本文来自一个简单的 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 会很不错。
【问题讨论】: