1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 12:59:36 +02:00

feat: Add validation for adventure type matching trip type

This commit is contained in:
Sean Morley 2024-07-09 13:43:32 -04:00
parent 374963f305
commit aaa83ea2c0
3 changed files with 19 additions and 14 deletions

View file

@ -6,7 +6,7 @@ class AdventureSerializer(serializers.ModelSerializer):
class Meta:
model = Adventure
fields = '__all__' # Serialize all fields of the Adventure model
fields = '__all__'
def to_representation(self, instance):
representation = super().to_representation(instance)
@ -19,9 +19,12 @@ class AdventureSerializer(serializers.ModelSerializer):
return representation
class TripSerializer(serializers.ModelSerializer):
adventures = AdventureSerializer(many=True, read_only=True, source='adventure_set')
class Meta:
model = Trip
fields = '__all__' # Serialize all fields of the Adventure model
# fields are all plus the adventures field
fields = ['id', 'user_id', 'name', 'type', 'location', 'date', 'is_public', 'adventures']