Skip to content

Commit

Permalink
Add Image to Fitness (#202)
Browse files Browse the repository at this point in the history
* add image to fitness

* add to model

* remove comments
  • Loading branch information
vcai122 authored Sep 15, 2023
1 parent 6bed369 commit fdd6328
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
14 changes: 12 additions & 2 deletions backend/penndata/management/commands/load_fitness_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
19 changes: 19 additions & 0 deletions backend/penndata/migrations/0007_fitnessroom_image_url.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
3 changes: 1 addition & 2 deletions backend/penndata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend/penndata/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Meta:
class FitnessRoomSerializer(serializers.ModelSerializer):
class Meta:
model = FitnessRoom
fields = ("id", "name")
fields = "__all__"


class FitnessSnapshotSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit fdd6328

Please sign in to comment.