Skip to content

Instantly share code, notes, and snippets.

@Nipun2016
Last active February 9, 2018 06:01
Show Gist options
  • Save Nipun2016/3ce5a45c505012d7754c89fc221db6a8 to your computer and use it in GitHub Desktop.
Save Nipun2016/3ce5a45c505012d7754c89fc221db6a8 to your computer and use it in GitHub Desktop.
def attachment_upload(instance, filename):
"""Stores the attachment in a "per module/appname/primary key" folder"""
return 'attachments/{app}_{model}/{pk}/{filename}'.format(
app=instance.content_object._meta.app_label,
model=instance.content_object._meta.object_name.lower(),
pk=instance.content_object.pk,
filename=filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment