Django objects.all()空查询集,在shell中不为空

[英]Django objects.all() empty query set, not empty in shell


I have been using Django for the past 2 years with no issues at all, I am no rookie.

我过去两年一直在使用Django而没有任何问题,我不是新手。

I recently created a new attribute for a model and added it to the mysql database.

我最近为模型创建了一个新属性,并将其添加到mysql数据库中。

Whenever I filter things using this attribute in my "views.py" i get an empty set, whenever I use the same exact line of code using "manage.py shell" it returns the expected queryset.

每当我在“views.py”中使用此属性过滤事物时,我得到一个空集,每当我使用“manage.py shell”使用相同的完整代码行时,它返回预期的查询集。

I have tried restarting the httpd service, the mysqld service and I have rebooted the system but nothing happens.

我已经尝试重新启动httpd服务,mysqld服务,我重新启动了系统,但没有任何反应。

Does anyone know how to bypass this issue?

有谁知道如何绕过这个问题?

Here's the code I used to debug this issue:

这是我用来调试此问题的代码:

Shell: It won't let me post pictures so here's the code:

Shell:它不会让我发布图片所以这里是代码:

>>>Session.objects.filter(cancellation_session=True)
>>>[<Session: Zumba Toning (Ladies)>]

views.py:

views.py:

def gym_day2(request):
    return HttpResponse(str(Session.objects.filter(cancellation_session=True)))

HttpResponse:

HttpResponse对象:

[]

Please Help!

请帮忙!

1 个解决方案

#1


1  

add . values or .values_list() after the statement , Session.objects.filter(cancellation_session=True).values(´field´)

加。语句后面的值或.values_list(),Session.objects.filter(cancellation_session = True).values('field')


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/09/29/f2d5efd3d14c96a4e771db476c1fbcf9.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号