django_auxilium.models.fields.files module

Collection of Django custom model field which have something to do with files

class django_auxilium.models.fields.files.OriginalFilenameRandomFileField(*args, **kwargs)

Bases: django_auxilium.models.fields.files.RandomFileNameWithFilenameFileFieldMixin, django.db.models.fields.files.FileField

class django_auxilium.models.fields.files.OriginalFilenameRandomImageField(*args, **kwargs)

Bases: django_auxilium.models.fields.files.RandomFileNameWithFilenameFileFieldMixin, django.db.models.fields.files.ImageField

class django_auxilium.models.fields.files.RandomFileField(*args, **kwargs)

Bases: django_auxilium.models.fields.files.RandomFileNameFileFieldMixin, django.db.models.fields.files.FileField

class django_auxilium.models.fields.files.RandomFileFieldDeconstructMixin[source]

Bases: object

Mixin for random filename file mixins which implements Django’s deconstruct to be Django-migrations compatible

deconstruct()[source]

Standard Django’s deconstruct in order to enable migrations support

class django_auxilium.models.fields.files.RandomFileNameFileFieldMixin(*args, **kwargs)[source]

Bases: django_auxilium.models.fields.files.RandomFileFieldDeconstructMixin

Mixing for a custom FileField which generates random filename

Parameters:upload_to (str) – String where uploaded files should be saved. Within that directory, random filename will always be selected.
class django_auxilium.models.fields.files.RandomFileNameWithFilenameFileFieldMixin(*args, **kwargs)[source]

Bases: django_auxilium.models.fields.files.RandomFileFieldDeconstructMixin

Mixing for a custom FileField which generates random filename and also stores original filename

Parameters:
  • upload_to (str) – String where uploaded files should be saved. Within that directory, random filename will always be selected.
  • filename_field (str) – Name of Django model field name where original filename should be stored
class django_auxilium.models.fields.files.RandomImageField(*args, **kwargs)

Bases: django_auxilium.models.fields.files.RandomFileNameFileFieldMixin, django.db.models.fields.files.ImageField

django_auxilium.models.fields.files.original_random_filename_upload_to(path, filename_field)[source]

Get upload_to compliant method which will always return a random filename however will also store the original filename in the model.

Parameters:
  • path (str) – The path relative to media where the filaname should be uploaded to
  • filename_field (str) – The name of the model attribute to which the original filename should be stored.
Returns:

upload_to – Django FileField’s upload_to compliant function

Return type:

function

django_auxilium.models.fields.files.random_filename_upload_to(path)[source]

Get upload_to compliant method which will always return a random filename.

This method can be used as Django’s FileField upload_to parameter. It returns an upload_to callable which will make sure the filename will always be random. This method also accepts a path parameter which will define where relative to the media folder, the file will be stored.

Parameters:path (str) – The path relative to media where the filename should be uploaded to
Returns:upload_to – Django FileField’s upload_to compliant function
Return type:function