1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-25 07:49:37 +02:00

Transportation changes

This commit is contained in:
Sean Morley 2024-08-19 16:32:08 -04:00
parent 2d4d98393c
commit dd8999a45f
9 changed files with 150 additions and 52 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-08-19 20:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('adventures', '0003_adventure_end_date'),
]
operations = [
migrations.AddField(
model_name='transportation',
name='end_date',
field=models.DateTimeField(blank=True, null=True),
),
]

View file

@ -55,6 +55,10 @@ class Adventure(models.Model):
updated_at = models.DateTimeField(auto_now=True)
def clean(self):
if self.date and self.end_date and self.date > self.end_date:
raise ValidationError('The start date must be before the end date. Start date: ' + str(self.date) + ' End date: ' + str(self.end_date))
if self.end_date and not self.date:
raise ValidationError('Adventures must have an end date. Adventure: ' + self.name)
if self.collection:
if self.collection.is_public and not self.is_public:
raise ValidationError('Adventures associated with a public collection must be public. Collection: ' + self.trip.name + ' Adventure: ' + self.name)
@ -100,6 +104,7 @@ class Transportation(models.Model):
rating = models.FloatField(blank=True, null=True)
link = models.URLField(blank=True, null=True)
date = models.DateTimeField(blank=True, null=True)
end_date = models.DateTimeField(blank=True, null=True)
flight_number = models.CharField(max_length=100, blank=True, null=True)
from_location = models.CharField(max_length=200, blank=True, null=True)
to_location = models.CharField(max_length=200, blank=True, null=True)
@ -109,6 +114,11 @@ class Transportation(models.Model):
updated_at = models.DateTimeField(auto_now=True)
def clean(self):
print(self.date)
if self.date and self.end_date and self.date > self.end_date:
raise ValidationError('The start date must be before the end date. Start date: ' + str(self.date) + ' End date: ' + str(self.end_date))
if self.end_date and self.date is 'null':
raise ValidationError('Transportations must have an end date. Transportation: ' + self.name)
if self.collection:
if self.collection.is_public and not self.is_public:
raise ValidationError('Transportations associated with a public collection must be public. Collection: ' + self.collection.name + ' Transportation: ' + self.name)

View file

@ -51,7 +51,7 @@ class TransportationSerializer(serializers.ModelSerializer):
fields = [
'id', 'user_id', 'type', 'name', 'description', 'rating',
'link', 'date', 'flight_number', 'from_location', 'to_location',
'is_public', 'collection', 'created_at', 'updated_at'
'is_public', 'collection', 'created_at', 'updated_at', 'end_date'
]
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']