[英]How to change instance in Django with hyperlinks?
我对Django有问题。 我想使用超链接更改模型的特定字段,但是我不知道该怎么做。 我试过了,但是什么也没做。
views.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')
urls.py:
path('svincola/<int:giocatore_id>/', views.sGiocatore, name='s_player'),
forms.py:
class EditGiocatoreForm(forms.ModelForm):
class Meta:
model = Giocatore
fields = ['fantasquadra']
lista.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 %}
进行更改后添加item.save()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.