Skip to content

Commit

Permalink
add to model
Browse files Browse the repository at this point in the history
  • Loading branch information
vcai122 committed Sep 13, 2023
1 parent c0a6121 commit d074c83
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 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,
),
]
1 change: 1 addition & 0 deletions backend/penndata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __str__(self):

class FitnessRoom(models.Model):
name = models.CharField(max_length=255)
image_url = models.URLField()
# TODO "portal/images" does not exist, add back images
# image = models.ImageField(upload_to="portal/images", blank=False)

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
3 changes: 0 additions & 3 deletions backend/penndata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,6 @@ def get(self, request):
datetime.time(hour=int(hours), minute=int((hours % 1) * 60))
for _, hours in self.open_times.values()
]
# TODO: either unify naming OR add a field to model to indicate which image to use
s3_image_name = room["name"].replace(" ", "_") + (".png" if "2nd" in room["name"] else ".jpg") if "Pool" not in room["name"] else "Pool.jpeg"
room["image"] = f"https://s3.us-east-2.amazonaws.com/penn.mobile/pottruck/{s3_image_name}"
return response


Expand Down

0 comments on commit d074c83

Please sign in to comment.