From ccf5541458db1cc4c1b46de95ee877ac67a0684a Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 26 May 2023 09:53:56 -0500 Subject: posts: added the concept of trips and a template for displaying them --- app/posts/admin.py | 3 ++- app/posts/migrations/0023_trip_order.py | 18 +++++++++++++++ app/posts/models.py | 3 ++- app/posts/templates/posts/trip_list.html | 36 ++++++++++++++++++++++++++++++ app/posts/urls/trip_urls.py | 15 +++++++++++++ app/posts/views/trip_views.py | 38 ++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 app/posts/migrations/0023_trip_order.py create mode 100644 app/posts/templates/posts/trip_list.html create mode 100644 app/posts/urls/trip_urls.py create mode 100644 app/posts/views/trip_views.py (limited to 'app/posts') diff --git a/app/posts/admin.py b/app/posts/admin.py index f9d679b..ea1d8a4 100644 --- a/app/posts/admin.py +++ b/app/posts/admin.py @@ -100,13 +100,14 @@ class PostAdmin(OSMGeoAdmin): @admin.register(Trip) class TripAdmin(OSMGeoAdmin): form = LGEntryForm - list_display = ('title', ) + list_display = ('title', 'order', 'date_started' ) prepopulated_fields = {'slug': ('title',)} search_fields = ('title',) fieldsets = ( ('Region', { 'fields': ( 'title', + 'order', 'subtitle', 'body_markdown', 'slug', diff --git a/app/posts/migrations/0023_trip_order.py b/app/posts/migrations/0023_trip_order.py new file mode 100644 index 0000000..75c643a --- /dev/null +++ b/app/posts/migrations/0023_trip_order.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.1 on 2023-05-24 10:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0022_trip_post_trip'), + ] + + operations = [ + migrations.AddField( + model_name='trip', + name='order', + field=models.PositiveIntegerField(blank=True, null=True, verbose_name='order'), + ), + ] diff --git a/app/posts/models.py b/app/posts/models.py index fb0ea46..7322881 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -47,12 +47,13 @@ class Trip(models.Model): date_started = models.DateField() date_ended = models.DateField() featured_image = models.ForeignKey(LuxImage, on_delete=models.SET_NULL, null=True, blank=True) + order = models.PositiveIntegerField("order", null=True, blank=True) def __str_(self): return self.title class Meta: - ordering = ('-date_started',) + ordering = ('-order',) def save(self, *args, **kwargs): created = self.pk is None diff --git a/app/posts/templates/posts/trip_list.html b/app/posts/templates/posts/trip_list.html new file mode 100644 index 0000000..02e4b67 --- /dev/null +++ b/app/posts/templates/posts/trip_list.html @@ -0,0 +1,36 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load pagination_tags %} +{% block pagetitle %}Luxagraf - Trips {% endblock %} +{% block metadescription %}Adventures {% endblock %} +{%block bodyid%}id="travels" class="archive"{%endblock%} +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}
+

Adventures

+
+

Trips

+

When we set out on them, we didn't think of any of these as "trips", but in hindsight, it does make a handy way of organizing things.

+

If you'd like to follow along, join the Friends of a Long Year newsletter, which will deliver some stories in your inbox.

+
+
{% autopaginate object_list 24 %} {% for object in object_list %} + {% endfor %} +
+
+ +{% endblock %} diff --git a/app/posts/urls/trip_urls.py b/app/posts/urls/trip_urls.py new file mode 100644 index 0000000..91d3c33 --- /dev/null +++ b/app/posts/urls/trip_urls.py @@ -0,0 +1,15 @@ +from django.urls import path, re_path, include +from django.views.generic.base import RedirectView + +from ..views import trip_views as views + +app_name = "trips" + +urlpatterns = [ + path( + r'', + views.TripListView.as_view(), + {'page':1}, + name="trip-list" + ), +] diff --git a/app/posts/views/trip_views.py b/app/posts/views/trip_views.py new file mode 100644 index 0000000..0079652 --- /dev/null +++ b/app/posts/views/trip_views.py @@ -0,0 +1,38 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.contrib.syndication.views import Feed +from django.apps import apps +from django.conf import settings + +from utils.views import PaginatedListView, LuxDetailView + +from ..models import Post, Trip + + +class TripListView(PaginatedListView): + """ + Return a list of Entries in reverse chronological order + """ + model = Trip + template_name = "posts/trips_list.html" + +class TripDetailView(LuxDetailView): + model = Post + slug_field = "slug" + + def get_queryset(self): + queryset = super(PostDetailView, self).get_queryset() + return queryset.select_related('location').prefetch_related('field_notes') + + def get_context_data(self, **kwargs): + context = super(PostDetailView, self).get_context_data(**kwargs) + related = [] + for obj in self.object.related.all(): + model = apps.get_model(obj.model_name.app_label, obj.model_name.model) + related.append(model.objects.get(slug=obj.slug, pub_date=obj.pub_date)) + context['related'] = related + return context + + def get_template_names(self): + obj = self.get_object() + return ["posts/%s_detail.html" % obj.get_post_type_display(), 'posts/post_detail.html'] -- cgit v1.2.3-70-g09d2