diff --git a/.env_sample b/.env_sample new file mode 100644 index 0000000..8f41861 --- /dev/null +++ b/.env_sample @@ -0,0 +1,2 @@ +ACCESS_KEY= +SECRET_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9c71830..019ef1d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ backups .ds_store core/staticfiles venv +.env diff --git a/codechallenges/migrations/0015_question_image.py b/codechallenges/migrations/0015_question_image.py new file mode 100644 index 0000000..5a8f17b --- /dev/null +++ b/codechallenges/migrations/0015_question_image.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.4 on 2021-08-12 20:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("codechallenges", "0014_auto_20210731_1954"), + ] + + operations = [ + migrations.AddField( + model_name="question", + name="image", + field=models.ImageField(blank=True, null=True, upload_to="questions"), + ), + ] diff --git a/codechallenges/models.py b/codechallenges/models.py index eb8274b..9cd0c88 100644 --- a/codechallenges/models.py +++ b/codechallenges/models.py @@ -60,6 +60,7 @@ class Question(models.Model): categories = models.ManyToManyField(Category, blank=True) authors = models.ManyToManyField(Author, blank=True) + image = models.ImageField(upload_to="questions", null=True, blank=True) def __str__(self): return self.title diff --git a/core/settings/base.py b/core/settings/base.py index e16541c..a2dc267 100644 --- a/core/settings/base.py +++ b/core/settings/base.py @@ -12,6 +12,9 @@ from pathlib import Path import os +from dotenv import load_dotenv + +load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -169,3 +172,15 @@ } CELERY_IMPORTS = "core.tasks" + +# S3 configuration +ACCESS_KEY = str(os.getenv("ACCESS_KEY")) +SECRET_KEY = str(os.getenv("SECRET_KEY")) + +DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" + +AWS_S3_ENDPOINT_URL = "http://minio.discretemath.ca/" +AWS_ACCESS_KEY_ID = os.environ.get("ACCESS_KEY", "access-key") +DEBUG = bool(os.environ.get("DJANGO_DEBUG", True)) +AWS_SECRET_ACCESS_KEY = os.environ.get("SECRET_KEY", "secret-key") +AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME", "core") diff --git a/polls/migrations/0003_auto_20210812_1958.py b/polls/migrations/0003_auto_20210812_1958.py new file mode 100644 index 0000000..fd861c1 --- /dev/null +++ b/polls/migrations/0003_auto_20210812_1958.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.4 on 2021-08-12 19:58 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("polls", "0002_auto_20210731_2003"), + ] + + operations = [ + migrations.AlterField( + model_name="multiplechoicequestion", + name="poll", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="multiple_choice_questions", + to="polls.poll", + ), + ), + ] diff --git a/requirements.txt b/requirements.txt index 18c03d0..394aa90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,4 +27,9 @@ sqlparse==0.4.1 toml==0.10.2 vine==5.0.0 wcwidth==0.2.5 -drf-yasg \ No newline at end of file +python-dotenv==0.19.0 +drf-yasg==1.20.0 +Pillow==8.3.1 +django-storages==1.11.1 +boto3==1.18.6 +botocore==1.21.6 \ No newline at end of file