FieldError — Unknown field(s): django-fluent-contents

1.6k views Asked by At

I'm a Python/Django noob. So any help will be appreciated.

Trying to use the 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)

I'm using South for migration.

    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'])

It looks like, no column is being created for the 'content' field.

So when I try to add a new 'Article' via django admin —

FieldError at /manage/article/article/add/

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

If I remove the fieldset from admin.py

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

admin.site.register(Article, ArticleAdmin)

The 'content' field is not shown in django admin

In reply to @vdboor.. Here's my installed apps ...

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',
) 

Also I'm using the example app from the repo as a guide... just removed the extra plugin model

FYI I'm using

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

Thank you for all the help :-)

2

There are 2 answers

0
vdboor On

It looks like, no column is being created for the 'content' field.

That is correct, the PlaceholderField becomes a reverse-generic-relation.

  • You can try removing the fieldsets declaration for now, and see what other error you get.
  • The repository also contains an example application, which you can run, and compare with your app.

Silly question, but is fluent_contents in the INSTALLED_APPS?

4
crazyzubr On

Still need to add extra fields. In the example shown, because the content is stored in a separate table - model 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"