Simple project to copy media files (intended for fixtures loads), pretty much as Django staticfiles does
Project description
django-media-fixtures
Simple project to copy media files (intended for fixtures loads), pretty much as staticfiles does.
Dependencies
Django >= 1.8 and < 3.0
Note: This is the last version supporting Python2!
Installation
pip install django-media-fixtures==0.1.0
Then, put ‘django_media_fixtures’ on your INSTALLED_APPS (on settings.py), just below ‘django.contrib.staticfiles’.
Usage
Just call manage command ‘collectmedia’, same as you do with collectstatic:
python manage.py collectmedia
And then all files on ‘media_fixtures’ folder in-apps will be copied to your MEDIA_ROOT.
So, when you create your fixture (for any ways, even through shell), put your file path matching the same tree folder view as your media file.
For instance,
YourModel.objects.get_or_create(image="uploads/yourmodel/img/example.jpg")
Where the file ‘example.jpg’ is on: yourappfolder/media_fixtures/uploads/yourmodel/img/example.jpg
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 Distribution
Built Distribution
Hashes for django-media-fixtures-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a912809860b77614e772d95b7153749c49f199dbe44be8ed1c1aa94a0f41c93e |
|
MD5 | 46c55d7204e4209c1041ca0d1b189738 |
|
BLAKE2b-256 | d210c32b173d5b1a6612f81d648675b9e9350abd0862e3238ee9194cfe045ddb |
Hashes for django_media_fixtures-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5a56e95472e6a2a1aa2b9bc5e7955632960f6c3fd6fb6f37a178ddd7dffc166 |
|
MD5 | 9a4efbcd67c59767088d2e18bfa4ba87 |
|
BLAKE2b-256 | 3771b03e8be079c503d01b2090f4c0924beb99f2c1b2b62e1c114d8f981d8f49 |