Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

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.

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

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:

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

views.py:

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

HttpResponse:

[]

Please Help!

like image 366
Bit68 Avatar asked Mar 12 '26 04:03

Bit68


1 Answers

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

like image 76
Jmint Avatar answered Mar 15 '26 01:03

Jmint



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!