2015-09-16 135 views
0

您好我正在爲我的網站使用Django框架。我有一個項目中的查看,將數據保存到數據庫(模型)。ValueError:無效文字爲int()錯誤

date_created = models.DateTimeField(auto_now_add=True) 
date_modified = models.DateTimeField(blank=True) 

有人能告訴我什麼問題:但是當我運行我的程序如下

ValueError: invalid literal for int() with base 10: '2015-08-24 12:27:58'

我views.py

class ProcessCheckBinningView(JSONResponseMixin, View): 
    #model = OrcAwaiverBin 
    def post(self, request, *args, **kwargs): 

     status = 'error' 
     msg = "this is from me" 

     post_body = json.loads(self.request.body) 
     fab_value = post_body['fab'] 
     technode_value = post_body['technode'] 
     layer_value = post_body['layer'] 

     print fab_value, technode_value, layer_value 
     print "submitted from the template f" 
     bin_object = OrcAwaiverBin() 
     # Record the last accessed date 
     bin_object.fab = fab_value 
     bin_object.technology = technode_value 
     bin_object.layer = layer_value 
     print "OKKKKK" 
     bin_object.created_by = '2015-08-24 12:27:58' 
     bin_object.date_modified = '2015-08-24 12:27:58' 
     bin_object.save() 
     return self.render_json_response(dict(status=status, msg=msg)) 

class CheckBinningView(TemplateView): 
    template_name = "orc_enable.html" 

    def get_context_data(self, *args, **kwargs): 
     context = super(CheckBinningView, self).get_context_data(*args, **kwargs) 
     fab = GroupProfile.objects.get(id=self.request.session['ACL_gid']).fab 
     gp = GroupProfile.objects.get(id=self.request.session['ACL_gid']) 
     context['fab'] = gp.fab 
     context['ngapp'] = "CMOD" 
     return context 

我的模型領域正在一個錯誤這裏?提前致謝。

+0

粘貼'OrcAwaiverBin'模型的models.py代碼 –

+0

更新了我的模型字段 – gentle

+0

@gentle請發佈完整的堆棧跟蹤!另外,你確定'self.request.session ['ACL_gid']'是整數,因爲你試圖通過'id'獲得'GroupProfile'對象嗎? – ozgur

回答

0

根據錯誤的建議,您應該聲明bin_object.created_by字段或bin_object.date_modified字段爲IntegerField

+0

沒有它的日期時間字段。也用模型更新了我的問題 – gentle

0

的問題是,作爲Aswin說我的模型只接受整數值。我試圖插入日期時間值。謝謝你們!

相關問題