Merge branch 'add_lineup'
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
{# <ul class="list-group">#}
|
{# <ul class="list-group">#}
|
||||||
<form action="{% url 'edit lineup' id=event.id%}" method="post">
|
<form action="{% url 'edit lineup' event_id=event.id%}" method="post">
|
||||||
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ positionings_formset.management_form }}
|
{{ positionings_formset.management_form }}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ from django.urls import path, include
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('edit/<int:id>', views.edit, name="edit lineup"),
|
path('edit/<int:event_id>', views.edit, name="edit lineup"),
|
||||||
]
|
]
|
||||||
@@ -8,7 +8,7 @@ from events.models import Event
|
|||||||
from players.models import Player
|
from players.models import Player
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def edit(request, id):
|
def edit(request, event_id):
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# create a form instance and populate it with data from the request:
|
# create a form instance and populate it with data from the request:
|
||||||
@@ -18,12 +18,21 @@ def edit(request, id):
|
|||||||
# process the data in form.cleaned_data as required
|
# process the data in form.cleaned_data as required
|
||||||
# ...
|
# ...
|
||||||
# redirect to a new URL:
|
# redirect to a new URL:
|
||||||
form.cleaned_data.pop('id') #FIXME this is a workaround, not sure why it is necessary
|
# form.cleaned_data.pop('id')
|
||||||
new_positioning, did_create = Positioning.objects.update_or_create(id=form['id'].data, defaults=form.cleaned_data)
|
|
||||||
|
if isinstance(form.cleaned_data['id'], Positioning):
|
||||||
|
positioning_id = form.cleaned_data.pop('id').id #FIXME this is a workaround, not sure why it is necessary
|
||||||
|
positioning = Positioning.objects.filter(id=positioning_id)
|
||||||
|
positioning.update(**form.cleaned_data)
|
||||||
|
did_create = False
|
||||||
|
else:
|
||||||
|
positioning = Positioning.objects.create(**form.cleaned_data, event_id=event_id)
|
||||||
|
did_create = True
|
||||||
|
return render(request, 'success.html', {'call_back':'edit lineup','id':event_id}, status=200)
|
||||||
# return render(request, 'success.html', {'call_back':'schedule'})
|
# return render(request, 'success.html', {'call_back':'schedule'})
|
||||||
event = Event.objects.get(id=id)
|
event = Event.objects.get(id=event_id)
|
||||||
players = Player.objects.all()
|
players = Player.objects.all()
|
||||||
qset = Positioning.objects.filter(event_id=id, order__isnull = False)
|
qset = Positioning.objects.filter(event_id=event_id, order__isnull = False)
|
||||||
formset = PositioningFormSet(queryset=qset)
|
formset = PositioningFormSet(queryset=qset)
|
||||||
for form in formset:
|
for form in formset:
|
||||||
for field in form.fields:
|
for field in form.fields:
|
||||||
|
|||||||
Reference in New Issue
Block a user