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:
parent
374963f305
commit
aaa83ea2c0
3 changed files with 19 additions and 14 deletions
|
@ -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']
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue