Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExerciseRoutineSerializer(serializers.ModelSerializer):
- exercise = ExerciseSerializer()
- class Meta:
- model = ExerciseRoutine
- fields = '__all__'
- def to_representation(self, obj):
- representation = super().to_representation(obj)
- exercise_representation = representation.pop('exercise')
- for key in exercise_representation:
- representation[key] = exercise_representation[key]
- return representation
- class RoutineSerializer(serializers.ModelSerializer):
- exercises = ExerciseRoutineSerializer(many=True)
- class Meta:
- model = Routine
- fields = '__all__'
- [
- {
- "id": 1,
- "routines": [
- {
- "id": 1,
- "exercises": [
- {
- "id": 1,
- "index": 0,
- "rest_time": 60,
- "repetition_goal": 10,
- "equipment": [
- {
- "id": 1,
- "equipment": "Fixed Bar"
- }
- ],
- "name": "Pull up"
- }
- ],
- "name": "RoutineName",
- "routine_type": "Regular"
- }
- ],
- "name": "WorkoutName"
- }
- ]
- [
- {
- "id": 1,
- "routines": [
- {
- "id": 1,
- "exercises": {
- 0 : {"id": 1, "rest_time": 60, "repetition_goal": 10,"equipment": [{..}], "name": "Pull up"},
- 1 : {"id": 13, "rest_time": 60, "repetition_goal": 10,"equipment": [{..}], "name": "Anotherexericse"}
- },
- "name": "RoutineName",
- "routine_type": "Regular"
- }
- ],
- "name": "WorkoutName"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement