What is the most efficient way to store a list in the Django models?

后端 未结 12 906
执笔经年
执笔经年 2020-11-28 01:27

Currently I have a lot of python objects in my code similar to the following:

class MyClass():
  def __init__(self, name, friends):
      self.myName = name
         


        
12条回答
  •  庸人自扰
    2020-11-28 01:49

    Would this relationship not be better expressed as a one-to-many foreign key relationship to a Friends table? I understand that myFriends are just strings but I would think that a better design would be to create a Friend model and have MyClass contain a foreign key realtionship to the resulting table.

提交回复
热议问题