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):