from django.views.generic import UpdateView, DetailView, ListView from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import Q from .models import Post from notes.models import Note class PostListView(LoginRequiredMixin, ListView): model = Post template_name = 'posts/post_table.html' def get_queryset(self): return Post.objects.filter(user=self.request.user).order_by("-needs_update") class PostNewView(LoginRequiredMixin, ListView): template_name = 'posts/post_list.html' def get_queryset(self): return Post.objects.filter(user=self.request.user).filter(is_live=0) def get_context_data(self, **kwargs): context = super(PostNewView, self).get_context_data(**kwargs) context['reviews'] = Note.objects.filter(plan__in=[1,2]) return context class PostTodoView(LoginRequiredMixin, ListView): template_name = 'posts/post_table.html' def get_queryset(self): qs = Post.objects.filter(user=self.request.user) qs = qs.filter(Q(needs_update=True) | Q(is_live=0)) unsorted_results = qs.all() return sorted(unsorted_results, key=lambda a: a.days_overdue(), reverse=True) def get_context_data(self, **kwargs): context = super(PostTodoView, self).get_context_data(**kwargs) context['reviews'] = Note.objects.filter(plan=1) return context class PostNotesView(LoginRequiredMixin, DetailView): model = Post