Login

Tag "rename"

Snippet List

Auto-rename duplicate fields

This is useful to run before you add a unique key to a character field that has duplicates in it. It just adds numbers to the end of the contents, so they will be unique. It takes a model class and a field name. The model class can be a South fake orm object, so this can be used inside data migrations.

  • rename
  • duplicate
  • south
  • unique-key
Read More

Use the primary key in FileField and ImageField filenames

Sometimes it is desirable to use values like the primary key when naming `FileField` and `ImageField` files, but such values are only available after saving the model instance. This abstract class implements a two-phase save in order to make this case easy. See the example in the docstring. Another solution would be to write a `save()` that requires `upload_to` to be a callable that checks for `instance.pk`, then calls it again after saving. However, this would require more work from the developer for simple cases.

  • imagefield
  • filefield
  • rename
  • upload_to
Read More

Image Standarization

Standarization of image fields (for being used when saving models). Automatically creates thumbnail. Change image name to /path/to/images/<my_field>-<id>.<ext>. Resize image and thumbnail to specified size (optionally can crop image to force size).

  • image
  • thumbnail
  • resize
  • rename
Read More

3 snippets posted so far.