rcnn/backend/apps/coaster/models.py
munsel 42197bfbc9 add coaster naming, challenge detail panel, and fix GeoJSON id bug
- Coaster editor: name input in top bar, saved/loaded with coaster data
- CoasterListPanel: show coaster name prominently alongside creator username
- ChallengesListPanel: drill-in detail view with center map, plan coaster,
  and accept challenge buttons; coaster count shown in list and detail
- AllCoastersPanel: coaster count visible in challenge entries
- Backend: add coaster_count to ChallengeMapSerializer and ChallengeDetailSerializer
- Fix: ChallengeLayer and ChallengesListPanel were reading f.properties.id
  (always undefined) instead of f.id — GeoFeatureModelSerializer puts the pk
  at the GeoJSON Feature level, not in properties
- Types: remove id from ChallengeMapProperties to reflect actual data shape

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 01:43:10 +02:00

54 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import uuid
from django.db import models
from django.conf import settings
class Coaster(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
creator = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='coasters',
)
challenge = models.ForeignKey(
'challenges.Challenge',
on_delete=models.CASCADE,
related_name='coasters',
)
name = models.CharField(max_length=255, blank=True, default='')
# Each anchor: {id, lon, lat, terrainAlt, heightOffset}
anchors = models.JSONField(default=list)
# Each strip: {id, startFrac, endFrac, accel_ms2}
acceleration_strips = models.JSONField(default=list)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
unique_together = [('creator', 'challenge')]
ordering = ['-updated_at']
def __str__(self):
return f'{self.creator.username} / {self.challenge_id}'
class CoasterRating(models.Model):
coaster = models.ForeignKey(
Coaster,
on_delete=models.CASCADE,
related_name='ratings',
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='coaster_ratings',
)
rating = models.PositiveSmallIntegerField() # 15
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
unique_together = [('coaster', 'user')]
def __str__(self):
return f'{self.user.username}{self.coaster_id} ({self.rating}★)'