2013-07-29 44 views
1

我試圖改變一個特定的主鍵項,如56,60,或75頁BOOL的的「確認」爲真,此代碼更改布爾真/假以網址:在Django

在模型的.py:

class PurchaseOrder(models.Model): 
    confirmed = models.NullBooleanField(null=True) 
在views.py

def confirm(request, itemnum): 
    item = get_object_or_404(PurchaseOrder, item_number = itemnum) 
    convert_item = str(itemnum) 
    PurchaseOrder.confirmed = True # This is not working 
    return HttpResponse('Item number '+ convert_item + ' changed to true') 

我能去的URL,如/ 60 /但它不是布爾更改爲true。

回答

4

你應該在你的模型的實例改變confirmed值,並將其保存:

def confirm(request, itemnum): 
    item = get_object_or_404(PurchaseOrder, item_number = itemnum) 
    item.confirmed = True 
    item.save() 

    return HttpResponse('Item number %s changed to true' % itemnum) 

希望有所幫助。

1

您應該確認您的商品;現在您正在嘗試確認整個Purchase Order課程。試試:

def confirm(request, itemnum): 
    item = get_object_or_404(PurchaseOrder, item_number = itemnum) 
    convert_item = str(itemnum) 
    item.confirmed = True # confirm your item 
    item.save() # Have to save it first 
    return HttpResponse('Item number '+ convert_item + ' changed to true')