Simple project to copy media files (intended for fixtures loads), pretty much as Django staticfiles does
Project description
sweelol
Simple project to copy media files (intended for fixtures loads) to the file storage, pretty much as the django.contrib.staticfiles app does.
Dependencies
Python 3.5+
Django 1.8+
Note: The version (v1.x.x) dropped support of Python2! If you still need Python2, please check the last version of v0.1.x series
Installation
pip install sweelol==1.2.1
Then, add the django_media_fixtures app in your settings.INSTALLED_APPS:
INSTALLED_APPS = [
...,
'django.contrib.staticfiles',
'sweelol',
...
]
Usage
The app provides a management command collectmedia:
python manage.py collectmedia
This works similarly to collectstatic: finds the media_fixtures subdirectory in the apps directories, and copies those files to the settings.MEDIA_ROOT.
So, when you create your fixture (by any means, even through shell), put your file path matching the same tree folder layout as it should be in the MEDIA_ROOT destination.
For instance:
YourModel.objects.get_or_create(image="uploads/yourmodel/img/example.jpeg")
Where the file example.jpeg is found in yourappfolder/media_fixtures/uploads/yourmodel/img/example.jpeg. The collectmedia management command will copy this file to uploads/yourmodel/img/example.jpeg inside the settings.MEDIA_ROOT directory.
Configurations
- MEDIA_FIXTURE_FOLDERNAME
You can change the media fixtures folder’s name on your apps, just putting this variable on settings.py.
MEDIA_FIXTURE_FOLDERNAME='my_media_fixtures_folder'
- MEDIA_FIXTURES_FILES_FINDERS
You can change the media fixtures finders, to search media files on other folders not in-app, for instance.
MEDIA_FIXTURES_FILES_FINDERS = ( 'django_media_fixtures.finders.FileSystemFinder', # combined with MEDIA_FIXTURES_FILES_DIRS, choose specific folders 'django_media_fixtures.finders.AppDirectoriesFinder', # default (if you do not set MEDIA_FIXTURES_FILES_FINDERS) )
- MEDIA_FIXTURES_FILES_DIRS
You can list specific media folders that you want to include on search.
MEDIA_FIXTURES_FILES_DIRS = [ "/home/user/myproject/mediafiles", "/opt/webfiles/common/", ]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file sweelol-1.2.1-py2-none-any.whl
.
File metadata
- Download URL: sweelol-1.2.1-py2-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f87f09e40802abdaf616aac51b11f0e58fb23ced7c526d073631788ff21efa79 |
|
MD5 | 43aab64b56ab78ca7c2ea44ec80feb07 |
|
BLAKE2b-256 | 0d969d34f9b04f06cef664acab17d2c4ae9e95125fba783a8e9355f324a2acad |