last day (15 days later) » 

9:16 PM
1
A: How to use models associated with a user in Django when rendering an HTML page

karthikr{{ request.user.taskitem_set.all }} would give you all the related task items. Now, to display it in your template: {% for task_item in user.taskitem_set.all %} {{ task_item.task_n }} {% endfor %} would display the list of tasks. Here is the documentation on reverse-queries on foreign ke...

 
So the _set.all works because I have defined a foreignkey?
 
Yes,, updating the qeustion with relevant links, so you can understand better.
 
Thanks! That is what I was looking for.
 
I've updated my issue, but am getting a set attribute error, any ideas?
 
9:16 PM
can you edit your question with the stack trace, and notify me here ?
 
I've updated the question, thanks
 
It is not taskn_set , it is taskitem_set - read the answer carefully, as it could be a little confusing.
 
Ah, ok. It now returns 'User' object has no attribute 'TaskItem_set'
 
now it is the case :)
taskitem_set
not TaskItem_set
 
Ok let me try :)
ooo, no errors so far. Going to try and call the data related to the user.
Annnnnd you're a genius. Thanks so much!
 
9:20 PM
well. dont know about the genius, but have done this enough times for sure :)
glad it helped
 
So the heuristic to follow when using the set.all is the model name lowercase?
 
yes
always lowercase
also, read up on related_name
that way you can do away with _set gibberish
 
sounds great. Thanks a lot. Enjoy your day.
 

last day (15 days later) »