【问题标题】:FieldError — Unknown field(s): django-fluent-contentsFieldError - 未知字段:django-fluent-contents
【发布时间】:2014-01-03 07:33:14
【问题描述】:

我是 Python/Django 新手。因此,我们将不胜感激。

尝试使用django-fluent-contents

models.py

​​>
from django.core.urlresolvers import reverse
from django.db import models
from fluent_contents.models.fields import PlaceholderField, PlaceholderRelation, ContentItemRelation
from fluent_contents.models import ContentItem


class Article(models.Model):
    title = models.CharField("Title", max_length=200)
    slug = models.SlugField("Slug", unique=True)
    content = PlaceholderField("article_content")

    placeholder_set = PlaceholderRelation()
    contentitem_set = ContentItemRelation()

    class Meta:
        verbose_name = "Article"
        verbose_name_plural = "Articles"

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('article-details', kwargs={'slug': self.slug})

admin.py

​​>
from django.contrib import admin
from article.models import Article
from fluent_contents.admin import PlaceholderFieldAdmin


class ArticleAdmin(PlaceholderFieldAdmin):
    prepopulated_fields = {'slug': ('title',)}

    fieldsets = (
        (None, {
            'fields': ('title', 'slug', ),
        }),
        ("Contents", {
            'fields': ('content',),
            'classes': ('plugin-holder',),
        })
    )

admin.site.register(Article, ArticleAdmin)

我正在使用South 进行迁移。

    db.create_table(u'article_article', (
        (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
        ('title', self.gf('django.db.models.fields.CharField')(max_length=200)),
        ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50)),
    ))
    db.send_create_signal(u'article', ['Article'])

看起来,没有为“内容”字段创建任何列。

所以当我尝试通过 django admin 添加新的“文章”时——

FieldError at /manage/article/article/add/

Unknown field(s) (content) specified for Article. Check fields/fieldsets/exclude attributes of class ArticleAdmin.

如果我从 admin.py 中删除字段集

class ArticleAdmin(PlaceholderFieldAdmin):
    prepopulated_fields = {'slug': ('title',)}

admin.site.register(Article, ArticleAdmin)

“内容”字段未显示在 django admin 中

回复@vdboor..这是我安装的应用程序...

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',

    # 3rd party apps
    'south',
    'django_extensions',
    'compressor',
    'debug_toolbar',
    'fluent_contents',
    'fluent_contents.plugins.text',
    'django_wysiwyg',

    # Project specific apps go here
    'article',
) 

我还使用来自 repo 的示例应用程序作为指南...刚刚删除了额外的插件模型

仅供参考,我正在使用

  Django==1.6
  MySQL-python==1.2.4
  South==0.8.4

感谢大家的帮助:-)

【问题讨论】:

    标签: django django-models django-admin django-fluent


    【解决方案1】:

    看起来,没有为“内容”字段创建任何列。

    没错,PlaceholderField 变成了反向泛型关系。

    • 您现在可以尝试删除fieldsets 声明,看看您会遇到什么其他错误。
    • 存储库还包含一个 example 应用程序,您可以运行它并与您的应用程序进行比较。

    愚蠢的问题,但fluent_contents 在 INSTALLED_APPS 中吗?

    【讨论】:

      【解决方案2】:

      仍然需要添加额外的字段。在example 中显示,因为content 存储在一个单独的表中 - 模型 ContentItem

      from fluent_contents.models.fields import PlaceholderField, PlaceholderRelation, ContentItemRelation
      
      class Article(models.Model):
          title = models.CharField("Title", max_length=200)
          slug = models.SlugField("Slug", unique=True)
          content = PlaceholderField("article_content")
      
          placeholder_set = PlaceholderRelation()  # <-- this
          contentitem_set = ContentItemRelation()  # <-- and this
      
          class Meta:
              verbose_name = "Article"
              verbose_name_plural = "Articles"
      

      【讨论】:

      • 添加了 PlaceholderRelation(),ContentItemRelation() 没有区别 :-(
      • 添加字段后进行迁移?
      • 我刚刚开始了一个新项目..并复制了“文章”应用程序以进行回购..使用南迁移“文章”应用程序..同样的问题...
      猜你喜欢
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      相关资源
      最近更新 更多