Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys, I am facing some problem to creating the dynamic lists of list by using django models.
subjects = ['M', 'E', 'B', 'C', 'CS', 'G', 'P', 'S', 'H', 'F']

neighbors = {}
neighbors['M'] = ['E', 'B', 'C', 'CS', 'G']
neighbors['E'] = ['M', 'B', 'C', 'CS', 'G', 'P', 'H']
neighbors['B'] = ['M', 'E', 'C', 'CS', 'G', 'P', 'S', 'H', 'F']
neighbors['C'] = ['M', 'E', 'B', 'CS', 'P', 'F']
neighbors['CS'] = ['M', 'E', 'B', 'C', 'G', 'P', 'H', 'F']
neighbors['G'] = ['M', 'E', 'B', 'CS', 'P', 'S', 'H']
neighbors['P'] = ['E', 'B', 'C', 'CS', 'G', 'S', 'H', 'F']
neighbors['S'] = ['B', 'G', 'P', 'H']
neighbors['H'] = ['E', 'B', 'CS', 'P', 'F', 'G']
neighbors['F'] = ['B', 'C', 'CS', 'P', 'H']


I want to convert this code in django models dynamically.

Suppose we get all subjects from django models like this
subjects = Subjects.objects.all()

and then want to make neighbors lists like above code. So how we can do that

What I have tried:

I want to make a lists of list by using single list. Please help me.
Posted
Comments
Maciej Los 17-Apr-20 11:01am    
What about?
subjects = [neighbors]

or
subjects = [neighbors['M'], neighbors['E'], ..., neighbors['F']]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900