mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-01 23:47:04 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -87,9 +87,7 @@ class RideRankingSerializer(serializers.ModelSerializer):
|
||||
"""Calculate rank change from previous snapshot."""
|
||||
from apps.rides.models import RankingSnapshot
|
||||
|
||||
latest_snapshots = RankingSnapshot.objects.filter(ride=obj.ride).order_by(
|
||||
"-snapshot_date"
|
||||
)[:2]
|
||||
latest_snapshots = RankingSnapshot.objects.filter(ride=obj.ride).order_by("-snapshot_date")[:2]
|
||||
|
||||
if len(latest_snapshots) >= 2:
|
||||
return latest_snapshots[0].rank - latest_snapshots[1].rank
|
||||
@@ -100,9 +98,7 @@ class RideRankingSerializer(serializers.ModelSerializer):
|
||||
"""Get previous rank."""
|
||||
from apps.rides.models import RankingSnapshot
|
||||
|
||||
latest_snapshots = RankingSnapshot.objects.filter(ride=obj.ride).order_by(
|
||||
"-snapshot_date"
|
||||
)[:2]
|
||||
latest_snapshots = RankingSnapshot.objects.filter(ride=obj.ride).order_by("-snapshot_date")[:2]
|
||||
|
||||
if len(latest_snapshots) >= 2:
|
||||
return latest_snapshots[1].rank
|
||||
@@ -149,28 +145,14 @@ class RideRankingDetailSerializer(serializers.ModelSerializer):
|
||||
"name": ride.park.name,
|
||||
"slug": ride.park.slug,
|
||||
"location": {
|
||||
"city": (
|
||||
ride.park.location.city
|
||||
if hasattr(ride.park, "location")
|
||||
else None
|
||||
),
|
||||
"state": (
|
||||
ride.park.location.state
|
||||
if hasattr(ride.park, "location")
|
||||
else None
|
||||
),
|
||||
"country": (
|
||||
ride.park.location.country
|
||||
if hasattr(ride.park, "location")
|
||||
else None
|
||||
),
|
||||
"city": (ride.park.location.city if hasattr(ride.park, "location") else None),
|
||||
"state": (ride.park.location.state if hasattr(ride.park, "location") else None),
|
||||
"country": (ride.park.location.country if hasattr(ride.park, "location") else None),
|
||||
},
|
||||
},
|
||||
"category": ride.category,
|
||||
"manufacturer": (
|
||||
{"id": ride.manufacturer.id, "name": ride.manufacturer.name}
|
||||
if ride.manufacturer
|
||||
else None
|
||||
{"id": ride.manufacturer.id, "name": ride.manufacturer.name} if ride.manufacturer else None
|
||||
),
|
||||
"opening_date": ride.opening_date,
|
||||
"status": ride.status,
|
||||
@@ -225,9 +207,7 @@ class RideRankingDetailSerializer(serializers.ModelSerializer):
|
||||
"""Get recent ranking history."""
|
||||
from apps.rides.models import RankingSnapshot
|
||||
|
||||
history = RankingSnapshot.objects.filter(ride=obj.ride).order_by(
|
||||
"-snapshot_date"
|
||||
)[:30]
|
||||
history = RankingSnapshot.objects.filter(ride=obj.ride).order_by("-snapshot_date")[:30]
|
||||
|
||||
return [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user