2015-10-16 27 views
0

我的任務是獲取文章列表。本文來自一個簡單的FeinCMS ContentType。文章列表表格FeinCMS內容類型

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 %} 

但我得到一個錯誤「對象類型‘Articels’有沒有屬性‘對象’...... 你有一個聰明的主意?這將是年級使用Feincms的ContentType。

回答

0

FeinCMS內容類型abstract,這意味着沒有數據並沒有與之相關的數據庫表。因此,沒有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() 
+0

嗨喬納斯,謝謝。 –