summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorlxf <sng@luxagraf.net>2022-02-06 13:26:32 -0500
committerlxf <sng@luxagraf.net>2022-02-06 13:26:32 -0500
commit13c0f7653855b4feb433eeeea513f41693cdb2af (patch)
tree06194ac19bae42acbc4d771ad64ed82403bca1ea /app
parent342a95c15aa3f94b6bb689c2bd7c7151db217691 (diff)
plan: added a new model to track places we might want to go.
Diffstat (limited to 'app')
-rw-r--r--app/planner/admin.py25
-rw-r--r--app/planner/migrations/0005_auto_20220206_1109.py40
-rw-r--r--app/planner/migrations/0006_campidea_state.py19
-rw-r--r--app/planner/models.py40
4 files changed, 122 insertions, 2 deletions
diff --git a/app/planner/admin.py b/app/planner/admin.py
index 5d533c8..910558a 100644
--- a/app/planner/admin.py
+++ b/app/planner/admin.py
@@ -4,11 +4,34 @@ from django.contrib.gis.admin import OSMGeoAdmin
from django.contrib.contenttypes.admin import GenericStackedInline
from utils.widgets import AdminImageWidget, LGEntryForm
-from .models import Camp, Trip
+from .models import Camp, Trip, CampIdea
from media.models import LuxImage
from utils.util import get_latlon
+@admin.register(CampIdea)
+class PlannerAdmin(OSMGeoAdmin):
+ list_display = ('name', )
+ #list_filter = ('has_water', )
+ # options for OSM map Using custom ESRI topo map
+ lat, lon = get_latlon()
+ default_lon = lon
+ default_lat = lat
+ default_zoom = 10
+ units = True
+ scrollable = False
+ map_width = 700
+ map_height = 425
+ map_template = 'gis/admin/osm.html'
+ openlayers_url = '/static/admin/js/OpenLayers.js'
+
+ class Media:
+ js = ('image-loader.js', 'next-prev-links.js')
+ #'product-loader.js',
+ css = {
+ "all": ("my_styles.css",)
+ }
+
@admin.register(Camp)
class PlannerAdmin(OSMGeoAdmin):
diff --git a/app/planner/migrations/0005_auto_20220206_1109.py b/app/planner/migrations/0005_auto_20220206_1109.py
new file mode 100644
index 0000000..dee19bf
--- /dev/null
+++ b/app/planner/migrations/0005_auto_20220206_1109.py
@@ -0,0 +1,40 @@
+# Generated by Django 3.2.7 on 2022-02-06 11:09
+
+import django.contrib.gis.db.models.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('planner', '0004_auto_20210815_1856'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='CampIdea',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200)),
+ ('slug', models.SlugField(blank=True, null=True)),
+ ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
+ ('notes', models.TextField(blank=True, null=True)),
+ ('notes_html', models.TextField(blank=True, null=True)),
+ ('date_added', models.DateField(auto_now_add=True)),
+ ],
+ options={
+ 'ordering': ('date_added',),
+ 'get_latest_by': 'date_added',
+ },
+ ),
+ migrations.AlterField(
+ model_name='camp',
+ name='slug',
+ field=models.SlugField(blank=True, null=True),
+ ),
+ migrations.AlterField(
+ model_name='trip',
+ name='slug',
+ field=models.SlugField(unique_for_date='date'),
+ ),
+ ]
diff --git a/app/planner/migrations/0006_campidea_state.py b/app/planner/migrations/0006_campidea_state.py
new file mode 100644
index 0000000..f0dbdea
--- /dev/null
+++ b/app/planner/migrations/0006_campidea_state.py
@@ -0,0 +1,19 @@
+# Generated by Django 3.2.7 on 2022-02-06 12:36
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('planner', '0005_auto_20220206_1109'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='campidea',
+ name='state',
+ field=models.CharField(default='none', max_length=40),
+ preserve_default=False,
+ ),
+ ]
diff --git a/app/planner/models.py b/app/planner/models.py
index df162c7..b9d06cf 100644
--- a/app/planner/models.py
+++ b/app/planner/models.py
@@ -15,7 +15,7 @@ from django.contrib.sitemaps import Sitemap
from django import forms
from django.template.defaultfilters import slugify
-from locations.models import Location
+from locations.models import Location, State
from utils.util import render_images, render_products, parse_video, markdown_to_html, extract_main_image
@@ -107,3 +107,41 @@ class Camp(models.Model):
self.slug = slugify(self.name)
self.notes_html = markdown_to_html(self.notes)
super(Camp, self).save(*args, **kwargs)
+
+
+class CampIdea(models.Model):
+ name = models.CharField(max_length=200)
+ slug = models.SlugField(blank=True, null=True)
+ point = models.PointField(null=True, blank=True)
+ notes = models.TextField(null=True, blank=True)
+ notes_html = models.TextField(null=True, blank=True)
+ state = models.CharField(max_length=40)
+ date_added = models.DateField(auto_now_add=True)
+
+ class Meta:
+ ordering = ('date_added',)
+ get_latest_by = 'date_added'
+
+ def __str__(self):
+ return self.name
+
+ def save(self, *args, **kwargs):
+ created = self.pk is None
+ if created:
+ self.state = State.objects.filter(geometry__contains=self.point).get().name
+ if not self.slug:
+ self.slug = slugify(self.name)
+ self.notes_html = markdown_to_html(self.notes)
+ super(CampIdea, self).save(*args, **kwargs)
+
+ @property
+ def longitude(self):
+ '''Get the site's longitude.'''
+ if self.point:
+ return self.point.x
+
+ @property
+ def latitude(self):
+ '''Get the site's latitude.'''
+ if self.point:
+ return self.point.y