python - Save object from template -
im creating music website. in website, add functionality of favorites users add songs favorite lists.
i have done don't know how save it. here code:
models.py
class song(models.model): is_favorite = models.booleanfield(default=false) def __str__(self): return self.song_title
views.py
def song_detail(request,song_id): song = song.objects.get(pk=song_id) favorite = song.is_favorite = true return render(request, 'song_detail.html', {'favorite':favorite})
song_detail.html
<button onclick="{{favorite}}">favourite</button>
while playing python shell, found problem: let s created song pk=1,
d = song.objects.get(pk=1) d.is_favorite=true d.save() y = song.objects.filter(is_favorite=true) print(y) ->s
the problem after making song's is_favorite = true, need save it. don't know how implement in code such when user clicks button boolean field changes true. thank you.
i solved myself!
i changed values of favorite views song.update(is_favorite=true).
Comments
Post a Comment