2011-10-20 63 views

回答

4

我發現我可以通過額外的參數在元類tiny_mce:

class Meta: 
     model = MyModel 
     widgets = { 
      'field_name': TinyMCE(mce_attrs={'content_css': "style.css"}), 
     } 
1

感謝szaman的答覆,我會盡力描述在Django的新版本初學者過程(1.9),如何自定義CSS文件添加到在Django管理的郵政型號命名爲「文本」領域

  1. 變化領域在0型到HTMLField

    from tinymce.models import HTMLField 
    
    class Post(models.Model): 
        title = models.TextField(default='') 
        subtitle = models.TextField(default='') 
        text = HTMLField(default='') 
    
  2. 與所需型號的應用程序,添加到admin.py文件:

    @admin.register(Post) # decorator for adding Django admin for Post 
    class PostAdmin(admin.ModelAdmin): 
        form = PostForm # attach custom form 
    
  3. 添加窗體類

    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",]}), 
         }