bartTC / django-attachments

A generic Django application to attach Files (Attachments) to any model.
BSD 3-Clause "New" or "Revised" License
296 stars 90 forks source link

Question: using django-attachments with a dynamic text editor #73

Closed atodorov closed 4 years ago

atodorov commented 4 years ago

@bartTC I have a question, or rather looking for other points of view and ideas.

The gist is that in a project of mine I have several Models which accept attachments as well as Markdown text. The attachments are nicely displayed for each Model's get.html page (all rendered via templates, these are mostly DetailViews). Now users want to have an image upload button in the JavaScript editor (it's SimpleMDE) akin to what the GitHub editor does - select a file from their PC and it will be uploaded to the server and then the appropriate Markdown will be automatically placed for them.

The way GitHub does it is by pinning the attachments to the user ID b/c that's about the only thing known at any given time. We can do the same with django-attachments but it opens a whole lot more questions how to deal with these files, see: https://github.com/kiwitcms/Kiwi/issues/977#issuecomment-674582268

This idea with per-user attachments also doesn't work well for my existing architecture where attachments are displayed in the details template for each object.

Any ideas, hints or recommendations from your side ?

bartTC commented 4 years ago

@atodorov are you interested in taking over the project? I don't have much time nor interest in this anymore, and don't use it anywhere. You have most interest in keeping it maintained.

atodorov commented 4 years ago

@atodorov are you interested in taking over the project?

Sure. My username on PyPI is also "atodorov", same as here on GitHub.

atodorov commented 4 years ago

FTR I have answered my original question. For anyone who comes looking here's my process:

1) From the JS editor upload files using existing API but attach them to request.user - works like a charm with existing django-attachments functionality 2) Use a post_save signal handler and move all attachments under the current user to the object being saved. This will help me keep tabs of files attached to the documents and possibly referenced via Markdown. I also have permissions handling, deletion, etc tied to the document object. I don't care how the URLs look like internally so I'm not changing them. This needs the patch in #75. 3) As an extra house-keeping measure I am going to run a cron job with the changes from #72 and remove all files under all users from time to time. This has a small risk of something going wrong for me and also doesn't require me to implement UI for attachments management for every user.

The details are in https://github.com/kiwitcms/Kiwi/pull/1859.

atodorov commented 4 years ago

@atodorov are you interested in taking over the project?

Sure. My username on PyPI is also "atodorov", same as here on GitHub.

@bartTC ping, any updates around adding me as a second maintainer ? Did this comment get lost between all of the other notifications?

bartTC commented 4 years ago

@atodorov it did, sorry. Going to setup everything tomorrow.