Package: paperclip
PaperclipAdd attachments to Django models, used inMapEntity.INSTALLInstalling from pypi (using pip)pip install paperclipInstalling from githubpip install -e git://github.com/makinacorpus/django-paperclip.git#egg=django-paperclipUPGRADEAfter upgrade to 0.4.0, if you want to enable links to Youtube/Soundcloud media,
you have to add an additional column to the database:ALTERTABLEpaperclip_attachmentADDCOLUMNattachment_videoVARCHAR(200)NOTNULLDEFAULT'';BASIC USAGEAddeasy_thumbnails,embed_videoandpapercliptoINSTALLED_APPSInclude urlsurlpatterns = [
    ...
    url(r'^paperclip/', include('paperclip.urls')),
    ...
]Include scripts in template<script src="{% static "paperclip/bootstrap-confirm.js" %}" type="text/javascript"></script>
<script src="{% static "paperclip/spin.min.js" %}" type="text/javascript"></script>
<script src="{% static "paperclip/paperclip.js" %}" type="text/javascript"></script>If you use bootstrap 3 or bootstrap 4, please includepaperclip/bootstrap-3-confirm.jsorpaperclip/bootstrap-4-confirm.jsinstead ofpaperclip/bootstrap-confirm.js.Include list and form in template{% include 'paperclip/attachment_list.html' with object=my_instance attachment_form_next=my_instance.get_detail_url %}Add paperclip models in one of your appsclass FileType(paperclip.models.FileType):
    pass

class Attachment(paperclip.models.Attachment):
    passConfigureDefine the following django setting:PAPERCLIP_ENABLE_VIDEO = False,
PAPERCLIP_FILETYPE_MODEL = 'myapp.FileType'
PAPERCLIP_LICENSE_MODEL = 'myapp.License'
PAPERCLIP_ATTACHMENT_MODEL = 'myapp.Attachment'
PAPERCLIP_ACTION_HISTORY_ENABLED = TrueMake migration and migrateTEMPLATESThree templates are embeded and can easily be overriden :paperclip/attachment_list.html: renders a table displaying attached files for an object and an upload form using the two following templatespaperclip/_attachment_table.html: renders a table displaying attached files for an object. You can add extra columns usingblock extra_column_headerandblock extra_column_datapaperclip/_attachment_form.html: renders an upload formTEMPLATETAGSTwo templatetags are provided :get_attachments_forResolves attachments that are attached to a given object. You can specify the variable name in the context the attachments are stored using theasargument. Default context variable name isattachments. You can filter on a specified FileType with the optionalonly_typeargument.Examples{% get_attachments_for my_instance as "my_attachments" %}
{% get_attachments_for my_instance as "my_attachments" only_type my_filetype_instance %}attachment_formRenders a “upload attachment” form.objargument is required and represents the instance to which you want to associate the file. A bound form can be given optionnaly with the argumentform. Important : aattachment_form_nextvariable is expected in context. If you want to use a custom form class, you can addattachment_form_classvariable in context tooExamples{% with object=my_instance attachment_form_next=my_instance.get_detail_url %}
    {% attachment_form object %}
{% endwith %}

OR

# views.py
...
context['object'] = my_instance
context['attachment_form_next'] = my_instance.get_detail_url(=)
context['attachment_form_class'] = MyAttachmentForm
...

# template
{% attachment_form object %}USE A CUSTOM FORMYou can use a custom django form by following this steps. Parenthetically, It’s the recommended solution if you want to use django-crispy-forms or django-floppyforms.Write your custom form :from paperclip.forms import AttachmentForm

class MyAttachmentForm(AttachmentForm):
    ...Note: To be sure to not break the form logic, we recommend to inherit from the nativepaperclip.forms.AttachmentForm.Add your form class in aattachment_form_classvariable of the main view contextcontext['attachment_form_class'] = MyAttachmentFormOverride'add_attachment'and'update_attachment'URLs to provide your custom form class in argumentsfrommy_app.formsimportMyAttachmentFormurlpatterns=[path('paperclip/',include('paperclip.urls')),...path('add-for/<str:app_label>/<str:model_name>/<int:pk>/','paperclip.views.add_attachment',kwargs={'attachment_form':MyAttachmentForm},name="add_attachment"),path('update/<int:attachment_pk>/','paperclip.views.update_attachment',kwargs={'attachment_form':MyAttachmentForm},name="update_attachment"),...]Note: Be sure to write these URLs after having included paperclip URLs.CLEANUPDeleting or changing an attachment does not remove the old attached file from disk.
From time to time you can clean obsolete files by running:./manage.py clean_attachmentsAUTHORSLICENSELGPLCHANGELOG2.7.2  (2023-02-21)Fix link between attachment and file is lost when updating old attachment (created in version <2.7.0) without title and random suffix2.7.1  (2023-02-17)Fix link between attachment and file is lost when updating old attachment (created in version <2.7.0) without random suffix2.7.0  (2023-02-15)Add safety checks on uploaded filesFix link to the project on Pypi when clicking the pypi badge (another pypi project is nameddjango-paperclip)Fix typo in test-supporting HTML files (nothing was broken though)2.6.1      (2022-07-07)Change setting names :PAPERCLIP_MIN_ATTACHMENT_HEIGHT,PAPERCLIP_MIN_ATTACHMENT_WIDTH=>PAPERCLIP_MIN_IMAGE_UPLOAD_WIDTH,PAPERCLIP_MIN_IMAGE_UPLOAD_HEIGHTFix check size of image only when it’s an image2.6.0      (2022-07-06)** New **AddPAPERCLIP_MAX_BYTES_SIZE_IMAGEmax size image formAddPAPERCLIP_MIN_ATTACHMENT_HEIGHTmin height image formAddPAPERCLIP_MIN_ATTACHMENT_WIDTHmin width image form2.5.1      (2022-07-05)Add blocks templates2.5.0      (2022-04-26)** New **Add field license on attachment2.4.3      (2022-04-08)Replace french column name to english column name2.4.2      (2022-03-29)** Fixes **Fix js init mode embed type should be File and not Youtube2.4.1      (2022-03-18)** Fixes **Fix form enable_link javascript2.4.0      (2022-01-10)** New **Support Django 4.02.3.4 (2021-12-13)New featuresAdd PAPERCLIP_RESIZE_ATTACHMENTS_ON_UPLOAD setting to enable resize attachments on uploadAdd PAPERCLIP_MAX_ATTACHMENT_WIDTH and PAPERCLIP_MAX_ATTACHMENT_HEIGHT to configure attachment resizing (defaults 1280px)2.3.3      (2021-09-03)** New **Display custom columns in attachment list2.3.2 (2021-06-09)Add a bootstrap-4-confirm2.3.1 (2021-06-03)** New **Support django 3.2 and python 3.9Drop support Python 3.52.2.6 (2020-11-24)** New **Support for django 3.12.2.5 (2020-05-15)** New **Support for django 2.2 and 3.0Drop Django 1.11, 2.0, 2.1 and python 2 supportSet automatic is_image db column2.2.4 (2020-03-10)** Fixes **Show attachment file, video or link widget as required2.2.3 (2019-12-31)** Fixes **Fix requirements for Django 22.2.2 (2019-10-08)** Fixes **Do not set author to current username by defaultFix mode preselection2.2.1 (2019-01-07)** Fixes **Fix permissions change, delete and delete_others2.2.0 (2018-11-07)** New **Support Python3, Django 2.0 and 2.1Drop Django 1.8, 1.9 and 1.10 support2.1.2 (2018-03-25)** New **Support Django 1.8 to 1.112.1.1 (2017-03-23)** Fixes **Fix releases required includes2.1.0 (2017-03-23)** New **From now, Attachment model support external picture URLs2.0.0 (2017-02-21)** BREAKING CHANGES **Provide an abstract model. Users are required to define their own
Attachment model1.0.0 (2017-01-14)** BREAKING CHANGES **Remove support of Django <= 1.7Rename parameter ‘module_name’ as ‘model_name’ in urls** New **Support Django 1.8Add initial migration (Caution! it depends on app settings)0.5.0 (2016-01-11)** New **Add a command to clean obsolete files0.4.1 (2015-03-20)** Fixes **Fix uploaded file modification0.4.0 (2015-03-20)** New **Allow to add links to Youtube or Soundcloud media0.3.0 (2015-03-18)** Removed (WARNING: backward incompatibility) **Totally remove crispy_forms and floppy_forms integration (you can now override the form by a custom one instead)** New **Allow usage of a custom form0.2.3 (2014-12-15)Handle swappable User modelEmbed spinner, bootstrap-confirm and add a bootstrap-3-confirmRemove crispy_forms dependency0.2.2 (2014-11-14)Fix permission check for attachments0.2.0 (2014-11-12)Allow to override file types from request.0.1.3 (2014-11-07)Fix packaging of locale files0.1.2 (2014-11-07)Fix upload regular expressions for author and legend0.1.1 (2014-11-03)Fix missing SVG media in package0.1.0 (2014-10-23)Initial working version