1
我正在为Django面试编写一个Web应用程序。从Django模型加载对象问题
在主页上,我正在寻找3个各种数据的列表。
这是载入主页时,我收到错误:
invalid literal for int() with base 10: 'Critical'
这是models.py:
from django.db import models
from django.utils import timezone
class Status(models.Model):
status_level=models.CharField(max_length=15)
def __str__(self):
return self.status_level
class Event(models.Model):
event_status=models.ForeignKey(Status)
event_title=models.CharField(max_length=50)
event_description=models.CharField(max_length=500)
event_flag=models.CharField(max_length=10)
date_active=models.DateField(default=timezone.now())
time_active=models.TimeField(default=timezone.now())
def __str__(self):
return self.event_title
目前有3点状态的对象,严重,中,低三档。
Views.py:
def index(request):
# home page
critical_list=Event.objects.filter(event_status='Critical')
medium_list=Event.objects.filter(event_status='Medium')
low_list=Event.objects.filter(event_status='Low')
context_dict={'critical':critical_list, 'medium':medium_list,'low':low_list}
return render(request, 'server_status/index.html',context_dict)
有很多的堆栈跟踪,所以我将发布两个相关的线,我认为是造成问题的原因:
在此行中出现的错误:
critical_list=Event.objects.filter(event_status='Critical')
,然后在堆栈跟踪的最后一行:
return int(value) ...
▼ Local vars
Variable Value
self
<django.db.models.fields.AutoField: id>
value
'Critical'
这就是我一直在寻找!谢谢。 现在到下一个错误... – cmackie21
你是不受欢迎的。既然你在这里还是新手,我是否可以指出在这里说'感谢'的首选方式是通过提高投票的好问题和有用的答案(一旦你有足够的声望这样做),并接受最有帮助的答案到任何问题你问(这也给你一个小小的提升你的声誉)。 – e4c5
谢谢,我从来没有注意到接受答案按钮,然后再指出它! – cmackie21