属性を持つSong
モデルがありvotes
ます。各オブジェクトの下にVote as Favourite
ボタンが表示されます。Song
ユーザーがVote as Favourite
ボタンをクリックvotes
すると、そのオブジェクトに関連付けられた属性Song
が 1 増加し、すべてのVote as Favourite
ボタンが無効になる必要があります。
HTML
{% for song in dj_song_list %}
<div>
<p><h3>{{ song.name }}</h3></p>
<p class="song_id">{{ song.song_id }}</p>
<button type="button" class="btn btn-default btn-custom" class='vote' onclick="update();">Vote as Favourite</button>
</div>
{% endfor %}
ajax.py
def update_votes(id):
song = Song.objects.get(song_id=id)
song.votes += 1
song.save()
@dajaxice_register
def update_disable(request, song_id):
update_votes(song_id)
dajax = Dajax()
dajax.assign('.vote', 'disabled', 'disabled')
return dajax.json()
JavaScript
function update(){
Dajaxice.hunt.update_disable(Dajax.process,{'song_id':$('.song_id').val()})
}
ボタン無効化部分は単独で使用すると問題なく動作します。しかし、update_votes()
関数内で関数を使用すると、update_disable()
何も機能しません。コードの何が問題になっていますか?