Closed sunjoomoon closed 7 years ago
Do you have simple code examples that trigger this? We're using parler + fluent-contents all the time, and it works just fine in your case..
Let me try to reproduce the issue with another sandbox in due time.
Sorry for the long one, Actually I am trying out 3 combinations - parler + contents + mptt. On a fresh reinstallation (entier project, clean DB), the same is produced. It simpley can not find the 'content' field.
FYR, mptt + contents, without using Parler, is working fine without any issues though.
class Page(MPTTModel, TranslatableModel):
parent = models.ForeignKey('self', null=True, blank=True,related_name='children')
translations = TranslatedFields(
title = models.CharField(_('Title'), max_length=255, unique=True),
slug = models.CharField(_('URL'), max_length=255,),
content = PlaceholderField("article_content"),
meta={
'unique_together': (
('slug', 'language_code'),
),
}
)
...
and in admins.py
from django.contrib import admin
...
from parler.admin import TranslatableAdmin, TranslatableStackedInline, TranslatableTabularInline
from parler.forms import TranslatableModelForm, TranslatedField
...
from mptt.admin import DraggableMPTTAdmin, MPTTModelAdmin
from mptt.forms import MPTTAdminForm
...
from fluent_contents.admin import PlaceholderFieldAdmin, PlaceholderEditorAdmin
...
class PageAdminForm(MPTTAdminForm, TranslatableModelForm):
pass
class PageAdmin(PlaceholderFieldAdmin, MPTTModelAdmin, TranslatableAdmin):
form = PageAdminForm
list_display = ('title',)
mptt_indent_field = "title"
mptt_level_indent = 20
fieldsets = (
(None, {
'fields': ('parent','title', 'slug','content',),
}),
)
def get_prepopulated_fields(self, request, obj=None):
return {'slug': ('title',)}
admin.site.register(Page,PageAdmin)
Ah, you don't have to place the PlaceholderField
in the translated fields block. It can be assigned to the shared model, as it will detect it's a TranslatableModel
.
Thanks, I did put that outside of the translations as below.
...
from fluent_contents.models.fields import PlaceholderField, PlaceholderRelation, ContentItemRelation
from fluent_contents.models import ContentItem
class Page(MPTTModel, TranslatableModel):
parent = models.ForeignKey('self', null=True, blank=True,related_name='children')
translations = TranslatedFields(
title = models.CharField(_('Title'), max_length=255, unique=True),
slug = models.CharField(_('URL'), max_length=255,),
meta={
'unique_together': (
('slug', 'language_code'),
),
}
)
content = PlaceholderField("article_content")
...
and now I get below issues when accessing the page in admin
u"Key 'content' not found in 'PageForm'"
and in the browser,
Exception Type: ValueError
Exception Value: The field 'content' does not refer to a placeholder object!
in template file, something like below
{% extends "base.html" %}
{% load i18n mptt_tags static staticfiles %}
{% load fluent_contents_tags %}
{% block page_title %} {{ object.title }}{% endblock %}
{% block content %}
<div class="detailview">
{% render_placeholder content %}
</div>
{% endblock %}
Trying out {% render_placeholder content %}
or {% render_placeholder object.content %}
or {% render_placeholder page.content %}
produce the same issue. Page is the app name.
what should I look into?
hmm.. I just tried something little, changed the content
to another one, fluent_content
, and then magically things just worked as expected. Guess something to do with fieldname content
which I did something in the first place and then that kept somewhere and got me the issue.
Thanks for the attention. Finally got mptt+Parler+Fluent-Contents working, I think.
Trying both fluent content and parler, following the doc from both repos returns below.
More details
Seems can not find the field, thus throwing out above. Any work around?