我有 Django 的问题。我想使用超链接更改模型的特定字段,但我不知道该怎么做。我试过这个,但它什么也没做。
视图.py:
def sGiocatore(request, giocatore_id):
item = get_object_or_404(Giocatore, pk=giocatore_id)
item.fantasquadra=None #or something else
return redirect('/sondaggio/fantasquadre')
网址.py:
path('svincola/<int:giocatore_id>/', views.sGiocatore, name='s_player'),
表格.py:
class EditGiocatoreForm(forms.ModelForm):
class Meta:
model = Giocatore
fields = ['fantasquadra']
列表.html:
{% for fantasquadra in elenco_fantasquadre %}
<p><b>{{ fantasquadra.nome_fantasquadra }}:</b></p>
<table id="customers">
{%for giocatore in elenco_giocatori%}
{% if giocatore.fantasquadra.nome_fantasquadra ==
fantasquadra.nome_fantasquadra %}
<tr><th>Nome</th><th>Cognome</th><th>N° Maglia</th><th>Squadra</th>
<th>Ruolo</th><th>Svincola</th></tr>
<tr><td>{{ giocatore.nome_giocatore }}</td>
<td>{{ giocatore.cognome_giocatore }}</td>
<td>{{giocatore.numero_maglia}}</td>
<td>{{giocatore.squadra.nome_squadra}}</td>
<td>{{giocatore.ruolo.ruolo}}</td>
<td><a href="/sondaggio/svincola/{{giocatore.id}}">Svincola</a></td></tr>
{% endif %}
{% endfor %}
</table>
{% endfor %}
犯罪嫌疑人X
相关分类