[英]how can I change the value of a booleanfield from static file using checkboxes
I've just started using django and I'm not so familiar with it. 我刚刚开始使用django,我对它并不熟悉。 This is my problem, I simply want to tick a checkbox and change the value of a booleanfield in the model which is default=false to true 这是我的问题,我只想勾选一个复选框并将模型中booleanfield的值更改为true = false为true
I'm trying to create a function from views.py, but if there is any way to do it directly from the static file where my checkbox is that would do the work for me either 我正在尝试从views.py创建一个函数,但如果有任何方法可以直接从我的复选框所在的静态文件中执行此操作,那将为我工作
This is my views.py 这是我的views.py
def check(request):
check = AddToCart.objects.get(orderd = request.GET['orderd'])
check.is_active = True
check.save()
This is the checkbox 这是复选框
Check: <input type="checkbox" name="checked" value="checked">
This is my model on models.py: 这是我在models.py上的模型:
class AddToCart(models.Model):
id = models.AutoField(primary_key=True, unique=True)
id_product = models.ForeignKey(Produkte, on_delete = models.DO_NOTHING)
quantity = models.IntegerField()
id_user = models.ForeignKey(User, on_delete = models.DO_NOTHING)
orderd = models.BooleanField(default=False)
@property
def cmimi_total(self):
return self.quantity * self.id_product.cmimi
I have some objects inside AddToCart and I want to change the boolean values of each of them to True when the checkbox is ticked. 我在AddToCart中有一些对象,我想在勾选复选框时将每个对象的布尔值更改为True。 I know my problem is just a basic one but as a newbie i could use some help. 我知道我的问题只是一个基本问题,但作为一个新手,我可以使用一些帮助。 Thank You ! 谢谢 !
I removed the checkbox and simply used a button to turn the boolean values in the model to True this is my views.py 我删除了复选框,只需使用一个按钮将模型中的布尔值转换为True, 这是我的views.py
def check_out(request):
if request.method == 'GET':
checked = AddToCart.objects.filter(id_user = request.user, orderd = False)
for a in checked:
a.orderd = True
a.save()
return HttpResponseRedirect('/browse/')
and the button into html file 并将按钮转换为html文件
<a type="button" href="/check/" class="btn btn-ge style-4 btn-warning btn-sm" id="buy_button">Buy Now</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.