Commit ad526c43 authored by Mathias Lund Ahrn's avatar Mathias Lund Ahrn
Browse files

Exercise now supports ownership and fileupload

parent e442ea82
......@@ -44,7 +44,7 @@ RUN DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME} \
&& echo "If you wish to alter the user credentials, then delete the user first."
# Create some exercises from seed data
RUN python manage.py loaddata seed.json
# RUN python manage.py loaddata seed.json
# Run wsgi server with gunicorn
CMD ["gunicorn", "secfit.wsgi", "--log-file", "-", "-b", "0.0.0.0:8000"]
......@@ -60,6 +60,7 @@ INSTALLED_APPS = [
"users.apps.UsersConfig",
"comments.apps.CommentsConfig",
"corsheaders",
"django_extensions"
]
MIDDLEWARE = [
......
# Generated by Django 3.1 on 2021-03-05 23:08
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import workouts.models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('workouts', '0003_rememberme'),
]
operations = [
migrations.AddField(
model_name='exercise',
name='owner',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='exercises', to='users.user'),
preserve_default=False,
),
migrations.CreateModel(
name='ExerciseFile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to=workouts.models.exercise_directory_path)),
('exercise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='files', to='workouts.exercise')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exercise_files', to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -142,6 +142,13 @@ class WorkoutFile(models.Model):
)
file = models.FileField(upload_to=workout_directory_path)
def exercise_directory_path(instance, filename):
return f"exercises/{instance.exercise.id}/{filename}"
class ExerciseFile(models.Model):
exercise = models.ForeignKey(Exercise, on_delete=models.CASCADE, related_name="files")
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name="exercise_files")
file = models.FileField(upload_to=exercise_directory_path)
class RememberMe(models.Model):
"""Django model for an remember_me cookie used for remember me functionality.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment