After doing a round of customer development for Makers Alley, we discovered that customers really wanted to communicate with makers about their pieces. In true MVP fashion, we got the first iteration out in a day by using django-postman to handle the user to user communication. Within a few days, we quickly discovered that text messages weren’t enough and we needed to support file attachments, otherwise makers can’t easily show their designs and customers can’t share what they like. Unfortunately, django-postman does not support attachments and we didn’t want to have to incorporate another messaging library. Another constraint was that we were already using the awesome jQuery File Upload library (in truth, a modified Django version by Sigurd Gartmann) to allow makers to upload images when managing their storefronts.
We wanted to leverage our existing file upload system but also incorporate it with the django-postman messaging library without having to modify any of the code in django-postman. We weren’t able to find anything on StackOverflow that dealt with this issue so we were left with writing our own. Here’s the approach we ended up taking that might come in handy for anyone else running into the same problem. The code needs some cleaning and I need to add some error checking but I’m sharing it with the excuse of “perfect is the enemy of good.”
We built a new app, postman_attachments, that would serve as the intermediary between the file upload piece and django-postman.
models.py: Attachment that would map the django-postman Message model to an uploaded file
api.py: Versions of pm_write and pm_broadcast that would do the same work as the original but would also map the attachments between
forms.py: In our case, we needed to tweak the FullReplyForm and created our own version that included a new “file_ids” field to hold the ids of the uploaded files. The full solution would need to make versions of the other forms included in django-postman.
The last minor thing we needed to do was update our urls.py file to override the standard django-postman urls to have them use our custom form.
I’d love to release this publicly but don’t have much experience creating standalone Django apps. If you have experience in open sourcing Django apps let me know - I’d love to get this out there as a standalone app or somehow incorporated into django-postman.