1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/factions/views.py

50 lines
1.3 KiB
Python
Raw Normal View History

2021-10-03 16:44:54 +02:00
# Create your views here.
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.views import generic
from factions.forms import FactionForm
from factions.models import Faction
def list_faction_redirect(request, *args, **kwargs):
first_faction: Faction = Faction.objects.first()
if not first_faction:
return redirect("factionadd")
return redirect(first_faction)
class FactionDetailView(generic.DetailView):
template_name = "factions/detail.html"
model = Faction
context_object_name = "faction"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data["factions"] = Faction.objects.all().select_related()
return data
class FactionCreateView(generic.CreateView):
template_name = "loot/edit.html"
model = Faction
form_class = FactionForm
context_object_name = "object"
class FactionEditView(generic.UpdateView):
template_name = "loot/edit.html"
model = Faction
form_class = FactionForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data['edit'] = True
return data
class FactionDeleteView(generic.DeleteView):
template_name = "common/confirm_delete.html"
model = Faction
success_url = reverse_lazy('factionlist')