lqez / django-summernote

Simply integrate Summernote editor with Django project.
MIT License
1.05k stars 226 forks source link

Question: How would you resize uploaded items? #47

Open jaddison opened 10 years ago

jaddison commented 10 years ago

Maybe a dumb question, but I'm looking at using this app and am wondering how resizing the image would work. Eg. I use sorl-thumbnail currently in my project, is there a way I could resize the image on upload?

In short, what if I wanted multiple sizes of the image for external purposes (think opengraph meta tags, social sharing sizing, etc.) as well as the image embedded in the field?

lqez commented 10 years ago

It sounds very useful. If we have an external callback in https://github.com/lqez/django-summernote/blob/master/django_summernote/views.py#L28-39, could it be useful for your task?

jaddison commented 10 years ago

To be honest, I'm not sure. If I'm not mistaken, images uploaded through summernote aren't directly associated with the model the summernote text fiedl data is saved to - ie. no ForeignKey or ManyToMany Field. This would make it hard to associate the image with the desired model anyhow for the purposes I'm talking about, I think?

In somewhat of a tangent, if I remove an image from an existing, saved summernote 'field' (textarea, whatever), the image that was uploaded doesn't get deleted (and can't, really) because there is no relation, correct?

lqez commented 10 years ago

Yes, you're totally right. There is no explicit relationship between attachments and texts by summernote, only urls exist. But every django model has its own content type, so we can make M2M between instances and attachments while uploading images.

jaddison commented 10 years ago

But every django model has its own content type, so we can make M2M between instances and attachments while uploading images.

Well, not when uploading images, because you won't have the opposite relation to save against until the model containing the text field is saved. So, you'd probably need to:

Off topic: Not sure on the best way to solve the above, but here's another thought: can you embed the Attachment's ID in the img tag as a data-summernote-attachment-id attribute? That might make it easier to add a management command to clean up old unused images (do a Django ORM regex filter to find all IDs currently in use and then delete Attachments not used?)

I suppose that you could use the img data-summernote-attachment-id attribute in a post_save signal for the developer's model with the text field to discover attachments used and then generate the M2M relations at that point? This way, you'd be given the developer the option to set up the signal if they wanted that relation set up at all.

Sorry for the unorganized brain dump - hope it helps a bit.

lqez commented 10 years ago

can you embed the Attachment's ID in the img tag as a data-summernote-attachment-id attribute?

Very reasonable approach. Thanks for dumping your brain. :-)

lqez commented 10 years ago

https://github.com/HackerWins/summernote/pull/478 This patch is very similar approach for containing meta attributes in <img> tag. I'll try out like this.

culshaw commented 10 years ago

I've embeded the Aviary editor into the plugin by adding an 'edit' button onto the image options (align left, center, right, 25% etc). The plugin then takes care of all image options too. https://developers.aviary.com/