Listing the Document ID from TinyDB

545 views Asked by At

I am trying to list out the content of db.json from this github (https://github.com/syntaxsmurf/todo/blob/main/main.py) on line 40 in main.py

Specifically this line

 for item in db:
        table.add_row( item["task"], item["completed_by"], item["status"]) #need to find the right command for pulling data out of tinyDB into these example strings

as you can see I can pull out and list the items just fine that I defined the names on Fx with item["task]

here is an example entry from db.json if you don't wanna take a look at github.

{
    "_default": {
        "1": {
            "completed_by": "Today",
            "status": "Pending",
            "task": "Shopping"
        }
}

Now what I am missing is how do I pull out the default generated ID "1" and list that? I wanna use that to for the user being able to remove it later.

Thank you I hope the question makes sense!

1

There are 1 answers

0
Andreas Frederiksen On BEST ANSWER

From reddit user azzal07: item.doc_id would be the correct implementation of this.

for item in db:
    table.add_row(str(item.doc_id), item["task"], item["completed_by"], item["status"])

Str() is for Rich table function it does not work if it's an int it would seem.