From fdd6328339185a43f1c89b23f3390d1f965dfd41 Mon Sep 17 00:00:00 2001 From: Vincent Cai <72774400+vcai122@users.noreply.github.com> Date: Fri, 15 Sep 2023 17:00:58 -0400 Subject: [PATCH] Add Image to Fitness (#202) * add image to fitness * add to model * remove comments --- .../management/commands/load_fitness_rooms.py | 14 ++++++++++++-- .../migrations/0007_fitnessroom_image_url.py | 19 +++++++++++++++++++ backend/penndata/models.py | 3 +-- backend/penndata/serializers.py | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 backend/penndata/migrations/0007_fitnessroom_image_url.py diff --git a/backend/penndata/management/commands/load_fitness_rooms.py b/backend/penndata/management/commands/load_fitness_rooms.py index 342896b9..b7797d47 100644 --- a/backend/penndata/management/commands/load_fitness_rooms.py +++ b/backend/penndata/management/commands/load_fitness_rooms.py @@ -12,11 +12,21 @@ def handle(self, *args, **kwargs): "Basketball Courts", "MPR", "Climbing Wall", - "1st floor Fitness", + "1st Floor Fitness", "Pool-Shallow", "Pool-Deep", ] for room in fitness_rooms: - FitnessRoom.objects.get_or_create(name=room) + obj, _ = FitnessRoom.objects.get_or_create(name=room) + if obj.image_url == "": + s3_image_name = ( + room.replace(" ", "_") + (".png" if "2nd" in room else ".jpg") + if "Pool" not in room + else "Pool.jpeg" + ) + obj.image_url = ( + f"https://s3.us-east-2.amazonaws.com/penn.mobile/pottruck/{s3_image_name}" + ) + obj.save() self.stdout.write("Uploaded Fitness Rooms!") diff --git a/backend/penndata/migrations/0007_fitnessroom_image_url.py b/backend/penndata/migrations/0007_fitnessroom_image_url.py new file mode 100644 index 00000000..44f89470 --- /dev/null +++ b/backend/penndata/migrations/0007_fitnessroom_image_url.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.19 on 2023-09-13 15:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("penndata", "0006_fitnesssnapshot_capacity"), + ] + + operations = [ + migrations.AddField( + model_name="fitnessroom", + name="image_url", + field=models.URLField(default=""), + preserve_default=False, + ), + ] diff --git a/backend/penndata/models.py b/backend/penndata/models.py index ce5fbb10..b73c9488 100644 --- a/backend/penndata/models.py +++ b/backend/penndata/models.py @@ -30,8 +30,7 @@ def __str__(self): class FitnessRoom(models.Model): name = models.CharField(max_length=255) - # TODO "portal/images" does not exist, add back images - # image = models.ImageField(upload_to="portal/images", blank=False) + image_url = models.URLField() def __str__(self): return str(self.name) diff --git a/backend/penndata/serializers.py b/backend/penndata/serializers.py index df90bc5b..5cffcc61 100644 --- a/backend/penndata/serializers.py +++ b/backend/penndata/serializers.py @@ -28,7 +28,7 @@ class Meta: class FitnessRoomSerializer(serializers.ModelSerializer): class Meta: model = FitnessRoom - fields = ("id", "name") + fields = "__all__" class FitnessSnapshotSerializer(serializers.ModelSerializer):