core.mixins.FilePathModelMixin module¶
Module with the core.mixins.FilePathModelMixin mixin.
- class core.mixins.FilePathModelMixin.FilePathModelMixin(*args, **kwargs)[source]¶
Bases:
ModelMixin adding functionality for managing a single storage file for a model class.
- file_path¶
The relative path in the storage where the file is stored. Can be null if no file has been saved (null does not collide with the unique constraint.).
- class Meta[source]¶
Bases:
objectMetadata class for the mixin, abstract to avoid makemigrations picking it up.
- abstract = False¶
- save(*args, **kwargs)[source]¶
Extended :django:
django.models.Model.save()method.Saves the data to storage if configured.
- open_file(mode='rb')[source]¶
Opens and returns the stored file as a filestream.
Note
Use inside a with block.
- Parameters:
mode (
str) – The mode the file is opened in.- Return type:
- Returns:
The filestream of the file.
- Raises:
FileNotFoundError – If the file_path is not set or the file is not found in the storage.
- delete_file()[source]¶
Deletes the file and sets file_path to None.
Intended for use in a signal.
- Return type:
- _meta = <Options for FilePathModelMixin>¶