mirror of
https://github.com/workhardbekind/workout-challenge.git
synced 2026-07-04 09:23:32 -04:00
first commit
This commit is contained in:
commit
e7f627801f
152 changed files with 35352 additions and 0 deletions
14
src-backend/workouts/serializers.py
Normal file
14
src-backend/workouts/serializers.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Workout
|
||||
|
||||
|
||||
class WorkoutSerializer(serializers.ModelSerializer):
|
||||
def validate(self, data):
|
||||
if data.get('sport_type') == 'Steps' and not data.get('steps'):
|
||||
raise serializers.ValidationError({'steps': 'Steps field is required when sport type is Steps'})
|
||||
return data
|
||||
|
||||
class Meta:
|
||||
model = Workout
|
||||
fields = ['id', 'sport_type', 'start_datetime', 'duration', 'duration_seconds', 'intensity_category', 'kcal', 'distance', 'steps', 'strava_id']
|
||||
read_only_fields = ['id', 'duration_seconds', 'strava_id'] #'duration_seconds',
|
||||
Loading…
Add table
Add a link
Reference in a new issue