Skip to content

Commit 445a030

Browse files
authored
adds ./manage.py upload_file (#7)
1 parent 8e72fb3 commit 445a030

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ckc/management/__init__.py

Whitespace-only changes.

ckc/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.core.files.base import ContentFile
2+
from django.core.files.storage import default_storage
3+
from django.core.management.base import BaseCommand
4+
5+
6+
class Command(BaseCommand):
7+
help = "Uploads a file to default storage"
8+
9+
def add_arguments(self, parser):
10+
parser.add_argument('source', type=str, help='Path of file to upload (on local disk)')
11+
parser.add_argument('destination', type=str, help='Remove path, where we are placing the file (default django storage)')
12+
13+
def handle(self, *args, **options):
14+
source = options['path']
15+
destination = options['destination']
16+
17+
print(f"Uploading: {source} ...")
18+
default_storage.save(destination, ContentFile(open(source, 'rb').read()))
19+
print("...done!")

0 commit comments

Comments
 (0)