2đź‘Ť
Since you’re here to learn, and your code is quite complex (I’d need all the code necessary to reproduce your problem, which includes models), I’m not going to answer with a code fix.
Instead, you will learn how to use a debugger, which will fix “I still don’t know where I am going wrong”.
-
Install ipdb, because it’s more convenient than just pdb,
pip install ipdb
. -
Set a breakpoint, in your view, add this line
import ipdb; ipdb.set_trace()
. -
Run the code in the devserver, the devserve should pause at the breakpoint, and show the code it’s paused at.
-
Get to know ipdb, type “h”, it will show a list of command, try to overread the documentation of each command, you can also check this article which includes a video.
-
Step through your code, by typing “n” in the debugger, the interpreter should move to the next line of code, “d” to step in, “u” to step out, etc … You can execute Python from the prompt at any time.
You will know what Python is doing exactly, fixing “I still don’t know where I am going wrong”. Also, you’ll become an invincible programmer (or something like that hahaha)