Django ForeignKey Instance vs Raw ID

后端 未结 1 1162
广开言路
广开言路 2020-12-31 03:24

Is there a way to not have to pass in a model instance for a foreign key when create a new model? Let\'s say I have the following models:

class Foo(models.M         


        
相关标签:
1条回答
  • 2020-12-31 04:11
    new_bar = Bar(info="something important", foo_id=12345)
    new_bar.save()
    

    You can also get foreign key values directly. Some kind of optimization.

    0 讨论(0)
提交回复
热议问题