automated push from the terminal
This commit is contained in:
3
tournament/admin.py
Normal file
3
tournament/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
tournament/apps.py
Normal file
5
tournament/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
class TournamentConfig(AppConfig):
|
||||
|
||||
name = 'tournament'
|
||||
24
tournament/migrations/0001_initial.py
Normal file
24
tournament/migrations/0001_initial.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.0.1 on 2024-03-05 17:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Tournament',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=240, verbose_name='name')),
|
||||
('description', models.CharField(max_length=240, verbose_name='description')),
|
||||
('rental_price', models.FloatField(default=999.99, verbose_name='rental_price')),
|
||||
('rented_user_id', models.IntegerField(verbose_name='rented_user_id')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
tournament/migrations/__init__.py
Normal file
0
tournament/migrations/__init__.py
Normal file
15
tournament/models.py
Normal file
15
tournament/models.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
|
||||
class Tournament(models.Model):
|
||||
|
||||
name = models.CharField("name", max_length=240)
|
||||
|
||||
description = models.CharField("description", max_length=240)
|
||||
|
||||
rental_price = models.FloatField("rental_price", default=999.99)
|
||||
|
||||
rented_user_id = models.IntegerField("rented_user_id")
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return self.name
|
||||
10
tournament/serializers.py
Normal file
10
tournament/serializers.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Tournament
|
||||
|
||||
class TournamentSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Tournament
|
||||
|
||||
fields = ['id', 'name', 'description', 'rental_price', 'rented_user_id']
|
||||
3
tournament/tests.py
Normal file
3
tournament/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
50
tournament/urls.py
Normal file
50
tournament/urls.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from django.urls import include, path
|
||||
from .views import TournamentCreate, TournamentList, TournamentDetail
|
||||
from .views import TournamentUpdate, TournamentDelete
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
path('', views.custom, name="custom"),
|
||||
|
||||
path('<int:pk>/', TournamentDetail.as_view(), name='retrieve-bike'),
|
||||
|
||||
path("reserve/<int:pk>/<int:user_pk>", views.reserveTournament, name="reserve-bike"),
|
||||
|
||||
path("return/<int:pk>/<int:user_pk>", views.returnTournament, name="return-bike"),
|
||||
|
||||
path('create/', TournamentCreate.as_view(), name='create-bike'),
|
||||
|
||||
path('update/<int:pk>/', TournamentUpdate.as_view(), name='update-bike'),
|
||||
|
||||
path('delete/<int:pk>/', TournamentDelete.as_view(), name='delete-bike'),
|
||||
|
||||
]
|
||||
|
||||
## path("<int:question_id>/vote/", views.vote, name="vote"),
|
||||
|
||||
## path("about", views.about, name="about"),
|
||||
|
||||
## ex: /polls/5/
|
||||
|
||||
## path("<int:question_id>/", views.detail, name="detail"),
|
||||
|
||||
## ex: /polls/5/results/
|
||||
|
||||
## path("<int:question_id>/results/", views.results, name="results"),
|
||||
|
||||
## ex: /polls/5/vote/
|
||||
|
||||
## path("<int:question_id>/vote/", views.vote, name="vote"),
|
||||
|
||||
## path('', TournamentList.as_view()),
|
||||
|
||||
## path('', login_required(direct_to_template), {'template': 'registration/login.html'}),
|
||||
|
||||
## path("custom", views.custom, name="custom"),
|
||||
|
||||
## (r'^foo/$', login_required(direct_to_template), {'template': 'foo_index.html'}),
|
||||
|
||||
## path('reserve/<int:pk>/<str:userid>/', TournamentUpdate.as_view(), name='reserve-bike')
|
||||
|
||||
## path('return/<int:pk>/', TournamentUpdate.as_view(), name='return-bike'),
|
||||
128
tournament/views.py
Normal file
128
tournament/views.py
Normal file
@@ -0,0 +1,128 @@
|
||||
from django.shortcuts import render
|
||||
from .models import Tournament
|
||||
from rest_framework import generics
|
||||
from .serializers import TournamentSerializer
|
||||
from django.http import HttpResponse
|
||||
from django.template import loader
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from django.shortcuts import redirect
|
||||
from django.shortcuts import reverse
|
||||
|
||||
## https://docs.djangoproject.com/en/4.2/intro/tutorial03/
|
||||
|
||||
class TournamentCreate(generics.CreateAPIView):
|
||||
|
||||
queryset = Tournament.objects.all(),
|
||||
|
||||
serializer_class = TournamentSerializer
|
||||
|
||||
class TournamentList(generics.ListAPIView):
|
||||
|
||||
queryset = Tournament.objects.all()
|
||||
|
||||
serializer_class = TournamentSerializer
|
||||
|
||||
class TournamentDetail(generics.RetrieveAPIView):
|
||||
|
||||
queryset = Tournament.objects.all()
|
||||
|
||||
serializer_class = TournamentSerializer
|
||||
|
||||
class TournamentUpdate(generics.RetrieveUpdateAPIView):
|
||||
|
||||
queryset = Tournament.objects.all()
|
||||
|
||||
serializer_class = TournamentSerializer
|
||||
|
||||
class TournamentDelete(generics.RetrieveDestroyAPIView):
|
||||
|
||||
queryset = Tournament.objects.all()
|
||||
|
||||
serializer_class = TournamentSerializer
|
||||
|
||||
def reserveTournament(request, pk, user_pk):
|
||||
|
||||
t = Tournament.objects.get(id=pk)
|
||||
|
||||
t.rented_user_id = user_pk # change field
|
||||
|
||||
t.save() # this will update only
|
||||
|
||||
##
|
||||
|
||||
latest_question_list = Tournament.objects.all()
|
||||
|
||||
context = {
|
||||
"latest_question_list": latest_question_list,
|
||||
"status_message": ("You have successfull reserved the %s." % t.name),
|
||||
}
|
||||
|
||||
if request.user.is_superuser:
|
||||
|
||||
template = loader.get_template("manage.html")
|
||||
|
||||
else:
|
||||
|
||||
template = loader.get_template("reserve.html")
|
||||
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
latest_question_list = Tournament.objects.all()
|
||||
|
||||
template = loader.get_template("reserve.html")
|
||||
|
||||
context = {
|
||||
"latest_question_list": latest_question_list,
|
||||
"status_message": ("You have successfull reserved the %s." % t.name),
|
||||
}
|
||||
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
def returnTournament(request, pk, user_pk):
|
||||
|
||||
t = Tournament.objects.get(id=pk)
|
||||
|
||||
t.rented_user_id = 0 # change field
|
||||
|
||||
t.save() # this will update only
|
||||
|
||||
##
|
||||
|
||||
latest_question_list = Tournament.objects.all()
|
||||
|
||||
context = {
|
||||
"latest_question_list": latest_question_list,
|
||||
"status_message": ("You have successfull returned the %s." % t.name),
|
||||
}
|
||||
|
||||
if request.user.is_superuser:
|
||||
|
||||
template = loader.get_template("manage.html")
|
||||
|
||||
else:
|
||||
|
||||
template = loader.get_template("reserve.html")
|
||||
|
||||
return HttpResponse(template.render(context, request))
|
||||
|
||||
#@login_required
|
||||
def custom(request):
|
||||
print("custom custom custom")
|
||||
|
||||
latest_question_list = Tournament.objects.all()
|
||||
|
||||
context = {
|
||||
|
||||
"latest_question_list": latest_question_list,
|
||||
}
|
||||
|
||||
if request.user.is_superuser:
|
||||
|
||||
template = loader.get_template("admin.html")
|
||||
|
||||
else:
|
||||
|
||||
template = loader.get_template("tournament.html")
|
||||
|
||||
return HttpResponse(template.render(context, request))
|
||||
Reference in New Issue
Block a user