开发者

adding code for a Django admin field

开发者 https://www.devze.com 2023-04-11 02:05 出处:网络
I have a tinymce textarea in my django admin and I need users to be able to upload images (via AJAX) that will be linked in this textarea.

I have a tinymce textarea in my django admin and I need users to be able to upload images (via AJAX) that will be linked in this textarea.

That 开发者_StackOverflow中文版would be accomplished by adding an "Image Upload" button (it's already working) in the top of the "Content" textarea.

What's the recommended way of doing that?

I can think on 2 solutions:

  1. extending change_form and replacing {% for fieldset in adminform %} for the actual fields... and when it's the content field, I add this value

  2. dynamically adding this button with javascript (find out where the content field is and add a <div> before it)

A better solution, if possible, would be to override just this specific field in the admin templates. Is that possible? Or are there better solutions?

PS: this field is not part of the DB (it just uploads one or more images, saves it to the storage and returns a link that will be included on the tinymce).


maybe you could use this formfield_overrides from the djangodocs
if not, create a subclass of modelform and overide the form of admin with ModelAdmin.form.

0

精彩评论

暂无评论...
验证码 换一张
取 消