Django using model of one app into other app's model
Asked Answered
X

1

1

Salam and hi,

I am using django and breaking two parts of project in two apps. However there is a reference field of one table as foreign key of other in terms of db. So how can I use one app's model primary key as foreign key of another app's model? And if is not possible then should I just make single app of all such apps. I am actually thinking apps as different modules/components of project, may be I will be adding some apps in future.

thanks

Xylol answered 6/11, 2011 at 2:52 Comment(0)
N
3

Either import the model from the other app, or refer to it by name in a string.

Naphthalene answered 6/11, 2011 at 2:55 Comment(4)
so then will I be able to use it like models.ForeignKey('importedModelName') ?Xylol
If you import the model then you can use the reference directly.Naphthalene
use the reference directly like I wrote in last in above line? like models.ForeignKey(className) ?Xylol
ok got it so after importing it will be similar to any other class/model inside that models file, thanksXylol

© 2022 - 2024 — McMap. All rights reserved.