How to store arbitrary name/value key pairs in a Django model?

后端 未结 5 538
没有蜡笔的小新
没有蜡笔的小新 2021-02-03 11:02

I have a fixed data model that has a lot of data fields.

class Widget(Models.model):
    widget_owner = models.ForeignKey(auth.User)
    val1 = models.CharField()
            


        
5条回答
  •  终归单人心
    2021-02-03 11:11

    When I had an object that could be completely customized by users, I created a field on the model that would contain some JSON in the column. Then you can just serialize back and forth when you need to use it or save it.

    However, it does make it harder to use the data in SQL queries.

提交回复
热议问题