2014-06-11 79 views
0

我無法保存數據庫中的更改。以及如何使用鏈接調用視圖。 我想編輯編輯鏈接的數據點擊,保存數據點擊保存鏈接並更新數據點擊移動鏈接。請幫助。'QuerySet'對象沒有'保存'屬性

這裏是我的views.py:

def answer(request): 
    info2 = Trans.objects.filter(transtype=8) 
    sid = 0 
if request.GET: 
    sid = request.GET.get('sid') 
bookdata = { "details" : info2, 'sid':int(sid) } 
info2.save() 
resp = render_to_response("account/answer.html", bookdata, context_instance=Context(request)) 
return resp 

HTML模板:

{% load i18n %} 

<!doctype html> 
<html> 
<body> 
<table border="1" style="width:800px"> 
<form action=" " method="POST"> 
<input type=hidden value= {{ s.id }} name ='sid'> 
<tr> 
{% for s in details %} 
</tr> 
<tr> 
<td> 
     {{ s.script }} 
    {% if s.id == sid %} 
     <input name="script" value="{{ s.script }}" /> 

    {% endif %} 
</td> 

<td> <a href="/accounts/answer/?sid={{ s.id }}" name="edit">Edit</a> </td> 
<td> <a href="/accounts/answer/?sid={{ s.id }}" name="save">Save</a> </td> 
<td> <a href="/accounts/answer/?sid={{ s.id }}" name="move">Move</a> </td> 
{% endfor %} 

</table> 

</body> 
</html> 

Models.py文件:

class Trans(models.Model): 
    transtype = models.ForeignKey(TransType) 
    title = models.CharField(max_length=200) 
    script = models.CharField(max_length=200) 
    movestatus= models.SmallIntegerField(default = 0) 
    created = models.DateTimeField(auto_now_add = True) 
    updated = models.DateTimeField(auto_now = True) 
    class Meta: 
      unique_together = (("transtype", "script"),) 
    def __unicode__(self): 
    return unicode(self.transtype) 
+1

您需要退後一步,看看您正在嘗試做什麼以及如何做到這一點。具體問題'info2'是queryset不是一個對象,所以你不能保存它。 – Rohan

回答

相關問題