Django: Why are quotes around the model in a ForeignKey definition

后端 未结 3 1304
一向
一向 2020-12-28 21:51

I want to know what the difference between these two foreignkey definitions are.

(1) MyFKField = models.ForeignKey(\'MyModel\')
(2) MyFKField = models.Foreig         


        
3条回答
  •  轮回少年
    2020-12-28 22:25

    Without quotes, it's a reference to a model either defined within the file or imported via import. With quotes, Django is made responsible for finding the model among all the models in all installed apps.

提交回复
热议问题