[英]django-tinymce HTMLField covering model field description in admin/add
The Issue问题
The name of the model field is not visible in Django's admin "add" page when using django-tinymce 's tinymce_models.HTMLField()
.使用django-tinymce的
tinymce_models.HTMLField()
时,模型字段的名称在 Django 的管理“添加”页面中不可见。 The Name:
field is in the picture, but the Description
field is not. Name:
字段在图片中,但Description
字段不在图片中。 How can I display the Description
text over the TinyMCE editor?如何在 TinyMCE 编辑器上显示
Description
文本?
The Model该模型
class Project(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=255)
description = tinymce_models.HTMLField()
started = models.DateField(blank=True)
Versions版本
A Bunch of Code一堆代码
https://codepen.io/anon/pen/xgqRqM https://codepen.io/anon/pen/xgqRqM
HTML is directly from Chrome Developer Tools on the Django admin page for adding this model. HTML 直接来自 Django 管理页面上的 Chrome 开发者工具,用于添加此模型。 CSS is both Django's and Tiny MCE's.
CSS 既是 Django 的,也是 Tiny MCE 的。 JS is from the Tiny MCE theme.
JS 来自 Tiny MCE 主题。 It doesn't seem to render correctly on Codepen so I'm not sure how useful it will be...
它似乎无法在 Codepen 上正确呈现,所以我不确定它会有多大用处...
Let me know if there's any more clarifying information I can provide.如果我能提供更多澄清信息,请告诉我。
More Pictures更多图片
I know the text Description:
is in the HTML:我知道文本
Description:
在 HTML 中:
Yes, a familiar issue.是的,一个熟悉的问题。 You need to move the left margin of TinyMCE 4 widget to the right.
您需要将 TinyMCE 4 小部件的左边距向右移动。 In my django-tinymce4-lite package I use the following dynamic CSS to set the widget position:
在我的django-tinymce4-lite包中,我使用以下动态 CSS 来设置小部件位置:
/* Fixes TinyMCE 4 widget position in Django admin */
.form-row .mce-tinymce {
margin-left: {{ margin_left }}px;
}
.form-row .mce-fullscreen {
margin-left: 0;
}
This is the view that generates the CSS:这是生成 CSS 的视图:
def css(request):
"""
Custom CSS for TinyMCE 4 widget
By default it fixes widget's position in Django Admin
:param request: Django http request
:type request: django.http.request.HttpRequest
:return: Django http response with CSS file for TinyMCE 4
:rtype: django.http.HttpResponse
"""
if 'grappelli' in settings.INSTALLED_APPS:
margin_left = 0
elif VERSION[0] == 1 and VERSION[1] <= 8:
margin_left = 106 # For old style admin
else:
margin_left = 170 # For Django >= 1.9 style admin
return render(request, 'tinymce/tinymce4.css', {'margin_left': margin_left}, content_type='text/css')
But if you don't support multiple Django versions, a static CSS with the necessary margin value will be enough.但是如果你不支持多个 Django 版本,一个具有必要边距值的静态 CSS 就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.