I am new to Django and come from the world of PHP. I am trying to βaddβ a field to a query set after computing things and donβt know how to do it. In PHP, I would just add a column to the array and store my stuff in it.
Here is my code:
def (id): mystuff_details = mystuff_details.objects.filter(stuff_id=id) newthing = ''; for mystuff in mystuff_details: newthing_lists = //some query to get another queryset for newthing_list in newthing_lists: newthing = newthing_list.stuffIwant //Here I want to make some computation, and ADD something to newthing, let say: to_add = (mystuff.score+somethingelse) //I've heard about the .append but I'm sure I'm screwing it up newthing.append(to_add)
So basically in my template I would like to call: {% for newthing in newthings_list%} {{newthing.to_add}} {% end%}
TL DR: I basically want to get a list of things from my database, and in this list of ADD objects there is a field that will contain the calculated value.
Let me know if this is unclear, it's hard for me to switch from php to django haha.
Thanks!
EDIT:
So, I'm trying to use dictionnary, but I miss the logic:
def (id): mystuff_details = mystuff_details.objects.filter(stuff_id=id) newthing = {}; for mystuff in mystuff_details: newthing_lists =
And then, when I get this work, I donβt know how to access it in the template:
{% for id in my_list %} {{newthing[id]}} ? Or something like newthing.id ? {% end %}
Thanks!
source share