I want to save a value in the database when the button is clicked without using a form.
I want to save the value in h2 to another model when the button is clicked.
What can i do?
TEMPLATE
<div class="widget-main">
<center><h2 name="urun" value="{{ urun.urun_adi }} ">{{ urun.urun_adi }}</h2></center>
</a>
<input type="submit" onclick="location.href='{% url 'sepete_ekle' %}'" value = "sepete ekle" class="btn btn-sm btn-default pull-right">
Sepete Ekle
</input>
<a href="" class="btn btn-sm btn-success">{{urun.fiyat}} TL</a>
</div>
VIEWS
def sepete_ekle(request):
if request.method == 'POST':
urun = request.POST["urun"]
status = 0
urunler = Siparis.objects.create(urun,status)
urunler.save()
messages.success(request, " Sepete Eklendi")
return redirect('/bayi/profil_duzenle')
else:
return HttpResponseRedirect("/")
MODEL
class Siparis(models.Model):
bayi = models.ForeignKey('auth.User', verbose_name='bayi', on_delete=models.CASCADE, related_name='bayi',limit_choices_to={'groups__name': "BayiGrubu"})
urun = models.ForeignKey(Urun, on_delete=models.CASCADE)
adet = models.IntegerField()
tarih = models.DateTimeField()
status = models.BooleanField()
class Meta:
verbose_name = 'Bayi Sipari?'
verbose_name_plural = 'Bayi Sipari?leri'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…