mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-19 04:49:37 +02:00
chore: Update Django server configuration and models for Adventure and Trip
This commit is contained in:
parent
933173883a
commit
c0900876c6
5 changed files with 98 additions and 5 deletions
3
backend/.gitignore
vendored
3
backend/.gitignore
vendored
|
@ -115,5 +115,4 @@ demo/react-spa/yarn.lock
|
||||||
|
|
||||||
*/media/*
|
*/media/*
|
||||||
|
|
||||||
/static/*
|
*/staticfiles/*
|
||||||
/staticfiles/*
|
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.utils.html import mark_safe
|
from django.utils.html import mark_safe
|
||||||
from .models import Adventure
|
from .models import Adventure, Trip
|
||||||
from worldtravel.models import Country, Region, VisitedRegion
|
from worldtravel.models import Country, Region, VisitedRegion
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ admin.site.register(Adventure, AdventureAdmin)
|
||||||
admin.site.register(Country, CountryAdmin)
|
admin.site.register(Country, CountryAdmin)
|
||||||
admin.site.register(Region, RegionAdmin)
|
admin.site.register(Region, RegionAdmin)
|
||||||
admin.site.register(VisitedRegion)
|
admin.site.register(VisitedRegion)
|
||||||
|
admin.site.register(Trip)
|
||||||
|
|
||||||
admin.site.site_header = 'AdventureLog Admin'
|
admin.site.site_header = 'AdventureLog Admin'
|
||||||
admin.site.site_title = 'AdventureLog Admin Site'
|
admin.site.site_title = 'AdventureLog Admin Site'
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-07-09 16:49
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('adventures', '0004_adventure_latitude_adventure_longitude'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='adventure',
|
||||||
|
name='trip_id',
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Trip',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('name', models.CharField(max_length=200)),
|
||||||
|
('type', models.CharField(max_length=100)),
|
||||||
|
('location', models.CharField(blank=True, max_length=200, null=True)),
|
||||||
|
('date', models.DateField(blank=True, null=True)),
|
||||||
|
('is_public', models.BooleanField(default=False)),
|
||||||
|
('user_id', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='adventure',
|
||||||
|
name='trip',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='adventures.trip'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-07-09 16:58
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('adventures', '0005_remove_adventure_trip_id_trip_adventure_trip'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='adventure',
|
||||||
|
name='type',
|
||||||
|
field=models.CharField(choices=[('visited', 'Visited'), ('planned', 'Planned'), ('featured', 'Featured')], max_length=100),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='trip',
|
||||||
|
name='type',
|
||||||
|
field=models.CharField(choices=[('visited', 'Visited'), ('planned', 'Planned'), ('featured', 'Featured')], max_length=100),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,6 +2,13 @@ from django.db import models
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
|
from django.forms import ValidationError
|
||||||
|
|
||||||
|
ADVENTURE_TYPES = [
|
||||||
|
('visited', 'Visited'),
|
||||||
|
('planned', 'Planned'),
|
||||||
|
('featured', 'Featured')
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# Assuming you have a default user ID you want to use
|
# Assuming you have a default user ID you want to use
|
||||||
|
@ -14,7 +21,7 @@ class Adventure(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
user_id = models.ForeignKey(
|
user_id = models.ForeignKey(
|
||||||
User, on_delete=models.CASCADE, default=default_user_id)
|
User, on_delete=models.CASCADE, default=default_user_id)
|
||||||
type = models.CharField(max_length=100)
|
type = models.CharField(max_length=100, choices=ADVENTURE_TYPES)
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
location = models.CharField(max_length=200, blank=True, null=True)
|
location = models.CharField(max_length=200, blank=True, null=True)
|
||||||
activity_types = ArrayField(models.CharField(
|
activity_types = ArrayField(models.CharField(
|
||||||
|
@ -24,10 +31,36 @@ class Adventure(models.Model):
|
||||||
link = models.URLField(blank=True, null=True)
|
link = models.URLField(blank=True, null=True)
|
||||||
image = models.ImageField(null=True, blank=True, upload_to='images/')
|
image = models.ImageField(null=True, blank=True, upload_to='images/')
|
||||||
date = models.DateField(blank=True, null=True)
|
date = models.DateField(blank=True, null=True)
|
||||||
trip_id = models.IntegerField(blank=True, null=True)
|
|
||||||
is_public = models.BooleanField(default=False)
|
is_public = models.BooleanField(default=False)
|
||||||
longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||||
latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||||
|
trip = models.ForeignKey('Trip', on_delete=models.CASCADE, blank=True, null=True)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if self.trip:
|
||||||
|
if self.is_public and not self.trip.is_public:
|
||||||
|
raise ValidationError('Public adventures must be associated with a public trip')
|
||||||
|
if self.trip.is_public and not self.is_public:
|
||||||
|
raise ValidationError('Adventures associated with a public trip must be public')
|
||||||
|
if self.user_id != self.trip.user_id:
|
||||||
|
raise ValidationError('Adventures must be associated with trips owned by the same user')
|
||||||
|
elif self.is_public:
|
||||||
|
raise ValidationError('Public adventures must be associated with a trip')
|
||||||
|
|
||||||
|
class Trip(models.Model):
|
||||||
|
id = models.AutoField(primary_key=True)
|
||||||
|
user_id = models.ForeignKey(
|
||||||
|
User, on_delete=models.CASCADE, default=default_user_id)
|
||||||
|
name = models.CharField(max_length=200)
|
||||||
|
type = models.CharField(max_length=100, choices=ADVENTURE_TYPES)
|
||||||
|
location = models.CharField(max_length=200, blank=True, null=True)
|
||||||
|
date = models.DateField(blank=True, null=True)
|
||||||
|
is_public = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if self.is_public:
|
||||||
|
if self.adventures.filter(is_public=False).exists():
|
||||||
|
raise ValidationError('Public trips cannot have private adventures')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue