Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django Summernote plugin upload image by userid #510

Open
simboli opened this issue Oct 23, 2024 · 0 comments
Open

Django Summernote plugin upload image by userid #510

simboli opened this issue Oct 23, 2024 · 0 comments

Comments

@simboli
Copy link

simboli commented Oct 23, 2024

I am using the Summernote plugin for Django and my target is to allow users to upload media inside the server. At the moment files are organized (by default) in a folder named with the upload date. Something like:

  • "ProjectName/media/django-summernote/2024-10-11/989d2f98-ad3c-47d6-9c07-e5f6d0c731e6.png"
  • "ProjectName/media/django-summernote/2024-10-17/13d646b8-d7cd-4e04-a76a-804a1ee0d090.jpg".

Is it possible to change the path and include the user_id in the path? Something like

  • "ProjectName/media/django-summernote/User100/989d2f98-ad3c-47d6-9c07-e5f6d0c731e6.png"
  • "ProjectName/media/django-summernote/User200/13d646b8-d7cd-4e04-a76a-804a1ee0d090.jpg".

I made these edits in the settings.py file

# Summernote plugin
def summernote_upload_to(request, filename):
 user = request.user
    
    # Create the dynamic path
 upload_path = f'user_upload/{user}'
    return os.path.join(upload_path)

SUMMERNOTE_CONFIG = {
    'attachment_upload_to': summernote_upload_to,
    'summernote': {
        'attachment_filesize_limit': 200 * 1000 * 1000, # specify the file size
        'width': '100%',
        'height': '480',
 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant