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

feat: Add validation for adventure type matching trip type

```
This commit is contained in:
Sean Morley 2024-07-09 13:26:45 -04:00
parent 8f0a8b2cc8
commit 374963f305

View file

@ -39,9 +39,11 @@ class Adventure(models.Model):
def clean(self): def clean(self):
if self.trip: if self.trip:
if self.trip.is_public and not self.is_public: if self.trip.is_public and not self.is_public:
raise ValidationError('Adventures associated with a public trip must be public') raise ValidationError('Adventures associated with a public trip must be public. Trip: ' + self.trip.name + ' Adventure: ' + self.name)
if self.user_id != self.trip.user_id: if self.user_id != self.trip.user_id:
raise ValidationError('Adventures must be associated with trips owned by the same user') raise ValidationError('Adventures must be associated with trips owned by the same user. Trip owner: ' + self.trip.user_id.username + ' Adventure owner: ' + self.user_id.username)
if self.type != self.trip.type:
raise ValidationError('Adventure type must match trip type. Trip type: ' + self.trip.type + ' Adventure type: ' + self.type)
def __str__(self): def __str__(self):
return self.name return self.name
@ -61,7 +63,7 @@ class Trip(models.Model):
if self.is_public: if self.is_public:
for adventure in self.adventure_set.all(): for adventure in self.adventure_set.all():
if not adventure.is_public: if not adventure.is_public:
raise ValidationError('Public trips cannot be associated with private adventures') raise ValidationError('Public trips cannot be associated with private adventures. Trip: ' + self.name + ' Adventure: ' + adventure.name)