guild-journal/guild/views/__init__.py

25 lines
875 B
Python

from datetime import date
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from guild.models import Adventure, Character, Player
# Create your views here.
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "guild/home.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
advs = Adventure.objects.prefetch_related("playsession_set", "master").all()
advs = sorted(
advs,
key=lambda x: x.last_session.date if x.last_session else date.min,
reverse=True,
)
context["adventures"] = advs
context["players"] = Player.objects.all()
context["characters"] = Character.objects.all()
return context