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

后端 未结 12 947
执笔经年
执笔经年 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:50

    Using one-to-many relation (FK from Friend to parent class) will make your app more scalable (as you can trivially extend the Friend object with additional attributes beyond the simple name). And thus this is the best way

提交回复
热议问题