Witam mam maly problem mam Widok :
def showMondayTable(request):
subjects = Subject.objects.all().filter(day=1)
return render(request, 'signs/monday.html', {'subjects':subjects,'locals': locals()})
i Widok:
def signMe(request, subject_id):
user = request.user
subject = get_object_or_404(Subject, id=subject_id)
sign = Sign()
user_is_participant = Sign.objects.all().filter(subject=subject_id, user=user).exists()
try:
sign.user = user
sign.subject = subject
finally:
if subject.actual_space < subject.space:
if user_is_participant == False:
subject.actual_space = subject.actual_space + 1
else:
pass
subject.save()
sign.save()
else:
pass
return render(request, 'signs/sign_success.html', {'user_is_participant': user_is_participant, 'locals': locals()})
Do tego template'a
{% extends 'base.html' %}
{% block scripts %}
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
{% endblock %}
{% block pageContent %}
<table class="table table-hover">
<thead>
<tr>
<th>Subject</th>
<th>Begin</th>
<th>End</th>
<th>Space</th>
<th>Sign</th>
</tr>
</thead>
{% for subject in subjects %}
<tbody>
<td>{{ subject.name }}</td>
<td>{{ subject.begin_at }}</td>
<td>{{ subject.end_at }}</td>
<td> {{ subject.actual_space }}/{{ subject.space }}</td>
<td><button class="btn-success subjectButton" day="monday" {% if user_is_participant > 0 %} disabled {% endif %} subjectId="{{ subject.id }}"> Zapisz </button><br></td>
<pre>{{ locals }}</pre>
</tbody>
{% endfor %}
</table>
<script>
$(document).ready(function () {
$('.subjectButton').click(function(){
var day = $(this).attr('day');
var subjectId = $(this).attr('subjectId');
var button = $(this);
button.prop('disabled', true);
button.text("Zapisano!");
console.log('dzien: '+day+', id: '+subjectId)
$.ajax({
url: 'http://localhost:8000/sign/'+day+'/signme/'+subjectId
}).done(function(data){
console.log('subject send');
console.log('recived data: '+ JSON.stringify(data));
});
})
})
</script>
{% endblock %}
Chcialem z widoku SignMe przekazac zmienna do monday.html ale nie moge tego zrobic gdyz template pobral zmienne z showMondayTable jak to obejsc? musze zablokowac przycisk jesli user jest zapisany ma zostac napis "Zapisano" i przycisk ma byc nieaktywny a terraz bo odswiezeniu strony przycisk jest nadal aktywny