Getting object value for AJAX call using Dajaxice

前端 未结 1 1362
-上瘾入骨i
-上瘾入骨i 2021-01-29 08:14

I have a Song model with a votes attribute. I have a Vote as Favourite button displayed below each Song object. I want when a

相关标签:
1条回答
  • 2021-01-29 08:49

    Here's how you can update the votes. You don't need update_votes to be an ajax function.

    def update_votes(song_id):
        song = Song.objects.get(id=song_id)
        song.votes += 1
        song.save()
    

    You can then call this function from within disable_button.

    @dajaxice_register
    def disable_button(request, song_id):
        update_votes(song_id)
        #disable the buttons
        return #whatever
    

    And are you sure you're using the right selector to disable your buttons?

    0 讨论(0)
提交回复
热议问题