3
I made a cursor to get the menus Parent of my application, then I want to iterate each menu Parent and get the menus associated with it. However, when passing the Parent parameter, the second course does not work.
from django.db import connection
parents=[]
with connection.cursor() as cursor:
cursor.execute("select parent from myapp_django_menu group by parent")
parents=cursor.fetchall()
print(parents)
for p in parents:
cursor.execute("select menu from myapp_django_menu where parent=%s group by menu",[p])
menu=cursor.fetchone()
print(menu)
the parameter p, is an item of a tuple in the format [('p1',), ('p2',)]
in this way, I understand that the problem should be the quotation marks, parentheses and commas.
How to make this p be accepted as a parameter?