Reputation: 6756
How can I change content_css option in django-tinymce for various objects? I mean that when I use tinymce for model1 then content_css is model1.css and when for model2 then model2.css. I use
Upvotes: 2
Views: 1362
Reputation: 3893
Thanks for the szaman's reply, I'll try to describe the process for beginners in new versions of Django (1.9), how to add custom css files to the field named 'text' in the Post model in the Django's admin
Change fields' type in models.py
to HTMLField
from tinymce.models import HTMLField
class Post(models.Model):
title = models.TextField(default='')
subtitle = models.TextField(default='')
text = HTMLField(default='')
In the application with the required model, add to admin.py
file:
@admin.register(Post) # decorator for adding Django admin for Post
class PostAdmin(admin.ModelAdmin):
form = PostForm # attach custom form
Add form's class
from tinymce.widgets import TinyMCE
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = '__all__' # required in Django (>=1.8)
widgets = {
'text': TinyMCE(mce_attrs={'content_css': ["path_to_css_file",]}),
}
Upvotes: 3
Reputation: 6756
I found out that I can pass extra arguments for tiny_mce in Meta class:
class Meta:
model = MyModel
widgets = {
'field_name': TinyMCE(mce_attrs={'content_css': "style.css"}),
}
Upvotes: 5