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

43 lines
1.1 KiB
Python
Raw Normal View History

2021-09-06 20:34:43 +02:00
# Create your views here.
2021-09-15 16:51:43 +02:00
from django.shortcuts import redirect
from django.views import generic
from locations.forms import LocationForm
from locations.models import Location
def list_location_redirect(request, *args, **kwargs):
first_location: Location = Location.objects.first()
if not first_location:
return redirect("locationadd")
return redirect(first_location)
class LocationDetailView(generic.DetailView):
template_name = "locations/detail.html"
model = Location
context_object_name = "location"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data["roots"] = Location.objects.with_tree_fields()
return data
class LocationCreateView(generic.CreateView):
template_name = "loot/edit.html"
model = Location
form_class = LocationForm
context_object_name = "object"
class LocationEditView(generic.UpdateView):
template_name = "loot/edit.html"
model = Location
form_class = LocationForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data['edit'] = True
return data