Issue
I have a Django model with a text field. I'm using a rich text editor (nicEdit) on the admin site to allow the client to easily enter markup into the field. I'd like to process the contents of the field and perform a few actions before anything is inserted into the database.
For example, I want to strip junk generated by MS Word, font tags, etc. I hope this part should be easy, but I'm not sure what to override or hook to get this working.
I also want to detect remotely-linked images, download a local copy to MEDIA_ROOT, and relink the img src to the local image. I'm not quite sure how to go about fetching the remote image; I thought django.Storage
might help but it looks like it's unable to fetch content from a remote URL.
Any suggestions?
Solution
Stripping the junk and such should be done with a custom formfield.
Downloading the images... there are multiple ways to fix that problem.
- If you choose to store the image location and original location in the database, than you should do it with a pre-save signal.
- If you choose to store the images locally directly, than you can make it part of the formfield aswell. Simply download all remote images and replace the urls with a local url.
Answered By - Wolph
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.