I'm using DjangoCMS 3.0 with Django 1.6 and django-filer.
I need a wysiwyg editor for some fields of my custom app. Since with the CMS I have installed djangocms-text-ckeditor, I tried to use it also for my model, like this:
from djangocms_text_ckeditor.fields import HTMLField
class Post(models.Model):
description = HTMLField(_('description'), blank=True, null=True)
This solution seems to work, but I can't add images inside it.
1) How can I add images inside CKeditor widget using cmsplugin_filer_image plugin?
2) Is it a good practice to use djangocms-text-ckeditor outside the CMS?
AFAIK, you can't.
Or by switching CKEditor to "HTML mode" and adding your <img> tag with the source hosted externally.
Likewise for all nested plugins (link, image, file, columns, etc.) which need a placeholder to handle the nested structure.
Yes, but not for complex contents, like medias. Then you can use a PlaceholderField but this is only manageable by staff users through the django-cms frontend editing feature.
Related
New to Django here, please bear with me if this question seems silly.
I'm in the process of designing (and afterwards developing) a blog website. I've identified three types of page that I will have on my blog (article, home, misc) each of these having a separate template.
Every new article would have its own text and images. Presumably I'd be using a single .html template to display many article texts.
Do I store the article texts and images in a separate model? If so, do I store the html of the article text (with all its formatting) in plain text and then render it in the view? What's the best way to do this?
Alternatively, I'd create a new template for every article, but this seems redundant.
You can use django-tinymce. It also provides good editor in your django admin.
Just install it with pip:
pip install django-tinymce
Add it in your INSTALLED_APPS:
INSTALLED_APPS = (
...
'tinymce',
)
Add tinymce.urls to urls.py for your project:
urlpatterns = [
...
url(r'^tinymce/', include('tinymce.urls')),
]
In your code:
from django.db import models
from tinymce.models import HTMLField
class MyModel(models.Model):
...
content = HTMLField()
I showed you the brief installation from documentation
I am studying Python and Django, my final goal is to create an administration panel that manages 2 things:
"dynamic article / item" (which can create types of forms to enter).
"dynamic taxonomies / tags" (which can create categories or groupers of the data "of the form type").
I have seen the documentation of DjangoCMS but I cannot find the names of these concepts, could you guide me?
thank you
You can do pretty much whatever you want to do. If you want to add to what a page gives you, extend the page;
http://docs.django-cms.org/en/latest/how_to/extending_page_title.html
I've used this to add images to pages, so you could use it to add tags or anything else you'd like.
Here's an example of attributing a colour to pages;
class PageColourExtension(PageExtension):
"""
Extend the page model with a background image field.
"""
page_colour = models.CharField(
_("Base colour"),
max_length=50,
null=True,
choices=COLOUR_CHOICES,
)
def __unicode__(self):
"""
Identify by the page it is tied to.
#return: page name
#rtype: str
"""
return '%s' % self.extended_object
extension_pool.register(PageColourExtension)
I'm not sure if djanog-cms is the right tool for your task. It's main purpose is to manage hierarchical pages, and the content on these pages. You need to keep in mind that this concept is already there, and cannot be changed, only extended.
For your specific case, I would recommend to create an own Article model, and then use the PlaceholderField, on your article model - it allows really dynamic content to be created, in the same fashion as when used on cms pages. See django-cms placeholder outside the cms docs for how to do that.
If you want to use django-cms and your custom application/article app alongside, you can use an app-hook to embed your urls under a cms page. See docs djanog-cms apphooks
I use third-party application (django-flatblocks) in my Django project. How can i change the name of the application in admin interface (grappelli)? I need russian name. I already tried to create localization files (.po.mo) and it is work fine in some parts of admin interface, but in breadcrumbs do not. I think grappelli does not use translation in some templates and the best way to resolve the problem is to replace django-flatblocks verbose_name in apps.py "on the fly". Can i do it somehow?
Found this in the official documentation did. The solution is so simple: For application users
To quote the Manual:
If you’re using “Rock ’n’ roll” in a project called anthology, but you
want it to show up as “Jazz Manouche” instead, you can provide your
own configuration:
# anthology/apps.py
from rock_n_roll.apps import RockNRollConfig
class JazzManoucheConfig(RockNRollConfig):
verbose_name = "Jazz Manouche"
# anthology/settings.py
INSTALLED_APPS = [
'anthology.apps.JazzManoucheConfig',
# ...
]
I want to pygmentize my text field python code in django admin template in a situation.
I have a python code block which is stored as a text field in django model.Here i stand with the situation of highlighting that python code with syntax in django admin change_form.html whenever you try to access that, it would be in proper syntax highlighiting style.
I have gone through some resources.
All are explained to make django template tag or filter with custom pygment template tag also, i got some nice article too.
1.http://od-eon.com/blogs/stefan/integrating-pygments-django/
2.http://djangosnippets.org/snippets/416/
But I am facing problem of using the template tags or filters in django admin change_form.html ?
Or How can we do the syntax highlighting through django model admin if this is the method should need to be passed (http://dpaste.com/hold/1280580/)?
Assuming you don't need ordering on the python code column, then you could simply render it using pygments API in a ModelAdmin method using list_display. Then you wouldn't need to touch django admin templates at all.
I would like to know the best way to replace a standard textarea field with a rich text editor in Django Admin?
There's an add-on Django application to provide TinyMCE support for Django admin forms without having to muck around with admin templates or Django newform internals.
Take a look on this snippet - basic idea is to include custom JS in your admin definitions which will replace standard text areas with rich-text editor.
For jQuery/FCKEditor such JS could look like that:
$(document).ready(function() {
$("textarea").each(function(n, obj) {
fck = new FCKeditor(obj.id) ;
fck.BasePath = "/admin-media/fckeditor/" ;
fck.ReplaceTextarea() ;
});
});
I'd say: define your own ModelAdmin class and overwrite the widget used for particular field, like:
class ArticleAdminModelForm(forms.ModelForm):
description = forms.CharField(widget=widgets.AdminWYMEditor)
class Meta:
model = models.Article
(AdminWYMEditor is a forms.Textarea subclass that adds WYMEditor with configuration specific to Django admin app).
See this blog post by Jannis Leidel to see how this widget can be implemented.
At the date of the post and the answers TinyMCE was quite popular (as it probably remains today).
But after some time ckeditor has appeared and many consider that a better alternative, including many SO users:
Compare TinyMCE and CKeditor for a Wiki
http://www.turnkeylinux.org/blog/tinymce-vs-ckeditor
There is also a 2013 review of WISIWYG editors with Django in Russian:
http://habrahabr.ru/company/htdt/blog/202782/
Currently the most straight forward way to use tinymce in django admin is to use Grappelli.
http://code.google.com/p/django-grappelli/
Grappelli is also a requirement for django-filebrowser so if you want the whole shebang you will gotta need it anyways.
class KindEditor(forms.Textarea):
class Media:
css ={
'all':(settings.STATIC_ROOT + 'editor/themes/default/default.css',)
}
js = (settings.STATIC_ROOT + 'editor/kindeditor-min.js',settings.STATIC_ROOT + 'editor/lang/zh_CN.js',)
def __init__(self):
attrs = {}
attrs['rel'] = 'kind'
super(KindEditor, self).__init__(attrs)
class NewsAdminForm(forms.ModelForm):
pass
class Meta:
model = News
widgets = {
'body':KindEditor()
}
class NewsAdmin(admin.ModelAdmin):
form = NewsAdminForm
admin.site.register(News, NewsAdmin)
Ok, to update a little this post, I would say that the easiest way to implement TinyMCE is to use the django-tinymce app. You must also download the JS files from the TinyMCE page. I got some errors with the django intenationalization, but downloading the laguage packs from the TinyMCE must be enough.
Install this package
pip install django-ckeditor
then run these commands to migrate.
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
finally restart your Django server.
Once you complete the above steps, you can see the rich text editor in your admin panel fields.