From 8e1fe8fc170bd004e76ac189922d8f811880f6ff Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sun, 15 Aug 2021 20:01:58 -0400 Subject: plan: added trip to planner so we can plan multiple possibilities and map to list view using leaflet --- app/planner/migrations/0003_trip.py | 22 +++++++++++++++++++++ app/planner/migrations/0004_auto_20210815_1856.py | 24 +++++++++++++++++++++++ app/planner/models.py | 23 ++++++++++++++-------- app/planner/templates/planner/list.html | 20 +++++++++++++++++-- 4 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 app/planner/migrations/0003_trip.py create mode 100644 app/planner/migrations/0004_auto_20210815_1856.py (limited to 'app/planner') diff --git a/app/planner/migrations/0003_trip.py b/app/planner/migrations/0003_trip.py new file mode 100644 index 0000000..41d410c --- /dev/null +++ b/app/planner/migrations/0003_trip.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.5 on 2021-08-15 18:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('planner', '0002_auto_20210725_1548'), + ] + + operations = [ + migrations.CreateModel( + name='Trip', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('date', models.DateField()), + ('slug', models.SlugField(unique_for_date='pub_date')), + ], + ), + ] diff --git a/app/planner/migrations/0004_auto_20210815_1856.py b/app/planner/migrations/0004_auto_20210815_1856.py new file mode 100644 index 0000000..c896a60 --- /dev/null +++ b/app/planner/migrations/0004_auto_20210815_1856.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.5 on 2021-08-15 18:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('planner', '0003_trip'), + ] + + operations = [ + migrations.AddField( + model_name='camp', + name='slug', + field=models.SlugField(blank=True, null=True, unique_for_date='pub_date'), + ), + migrations.AddField( + model_name='camp', + name='trip', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='planner.trip'), + ), + ] diff --git a/app/planner/models.py b/app/planner/models.py index f5bb042..3c527be 100644 --- a/app/planner/models.py +++ b/app/planner/models.py @@ -13,13 +13,26 @@ from django.apps import apps from django.conf import settings from django.contrib.sitemaps import Sitemap from django import forms +from django.template.defaultfilters import slugify from locations.models import Location from utils.util import render_images, render_products, parse_video, markdown_to_html, extract_main_image + +class Trip(models.Model): + name = models.CharField(max_length=200) + date = models.DateField() + slug = models.SlugField(unique_for_date='pub_date') + + def __str__(self): + return self.name + + class Camp(models.Model): + trip = models.ForeignKey(Trip, on_delete=models.SET_NULL, null=True, blank=True) name = models.CharField(max_length=200) + slug = models.SlugField(unique_for_date='pub_date', blank=True, null=True) date_arrive = models.DateField('Arrival Date') date_depart = models.DateField('Departure Date', blank=True, null=True) distance_from_previous = models.FloatField(null=True, blank=True) @@ -73,14 +86,6 @@ class Camp(models.Model): def get_content_type(self): return ContentType.objects.get(app_label="posts", model="post") - def get_issue_str(self): - issue = self.issue - if self.issue < 100: - issue = "0%s" % self.issue - if self.issue < 10: - issue = "00%s" % self.issue - return issue - @property def get_previous_published(self): return self.get_previous_by_date_arrive() @@ -104,5 +109,7 @@ class Camp(models.Model): def save(self, *args, **kwargs): created = self.pk is None + if not self.slug: + self.slug = slugify(self.name) self.notes_html = markdown_to_html(self.notes) super(Camp, self).save(*args, **kwargs) diff --git a/app/planner/templates/planner/list.html b/app/planner/templates/planner/list.html index 8575d4a..12b72a3 100644 --- a/app/planner/templates/planner/list.html +++ b/app/planner/templates/planner/list.html @@ -16,7 +16,23 @@ {% if object.has_electric %}
  • electric
  • {% endif %} {% endfor %} -
    - +
    {% endblock %} + + {% block js %} + + + +{% endblock %} -- cgit v1.2.3-70-g09d2