سؤال

I have a list containing some objects that i want to display in django tables 2 but as a result i got the - in all the columns. My list is like this format [[<Person>],[<Person>]]

Reading the documentation I've found that this format works :

data = [
    {"name": "Bradley"},
    {"name": "Stevie"},
]

How can I get a format like this knowing that my data is dynamic?

Update : I tried this :

for x in person_list:
        for y in x:
            data=[ 
                   {"firstname": y.firstname},
                   {"surname":y.surname},
                   ]

The problem is now it displays every field in a row, I mean first name in row and surname in another one. How to append to the same data ?

هل كانت مفيدة؟

المحلول 2

Ok so I found the solution to this inspired by this :

d={}
    dlist=[]
    for x in person_list:
        for y in x:
            d['firstname']=y.firstname
            d['lastname']=y.lastname
            dlist.append(d)

And it works like a charm !

نصائح أخرى

Try to produce your data table manually I suppose person has first_name field

data=[{"name": x.first_name} for x in persons_list]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top