carom-server/billard/views.py

54 lines
1.4 KiB
Python

from billard.serializers import *
from .models import LocationData
from rest_framework import viewsets
from django.shortcuts import render
from django.views import generic
from django.views.generic.detail import DetailView
from django.contrib.auth.decorators import login_required
class ClientViewSet(viewsets.ModelViewSet):
queryset = LocationData.objects.all()
serializer_class = ClientSerializer
class LocationViewSet(viewsets.ModelViewSet):
queryset = LocationData.objects.all()
serializer_class = LocationSerializer
class TableViewSet(viewsets.ModelViewSet):
queryset = LocationData.objects.all()
serializer_class = TableSerializer
class LocationDataViewSet(viewsets.ModelViewSet):
queryset = LocationData.objects.all()
serializer_class = LocationDataSerializer
class IndexView(generic.ListView):
model = LocationData
class LocationDataDetailView(DetailView):
model = LocationData
@login_required
def index(request):
loc = 1
if request.POST:
loc = request.POST['location-selector']
locations = Location.objects.order_by('code')
clients = Client.objects.filter(location_id=loc).order_by('id')
context = {
'range': range(1, 3),
'locations': locations,
'clients': clients,
'location_id': int(loc),
}
return render(request, 'billard/index.html', context=context)