Login

Tag "uploads"

Snippet List

Unique naming for file uploads

This snippit can be used to generate unique file names for uploads. `upload_to` allows a callable, but only provides two arguments: `instance` and `filename`. In order to prevent dumping all of the files for a model into one directory, this utilizes the `partial` decorator from `functools`, which essentially allows adding an extra argument to the function. The returned path will be of the form: `[model name]/[field_name]/[random hash].[filename extension]`

  • files
  • path
  • naming
  • uploads
Read More

1 snippet posted so far.