I made a cursor to get the parent menus of my application, then I want to iterate each parent menu and get the menus associated with it. However, passing parent with 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)
Parameter p, is an item of a tuple in the format [('p1',), ('p2',)]
in this way, I understand that the problem must be the quotation marks, parentheses and commas.
How to make this p be accepted as a parameter?