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']