[Answer]-Django import error between 2 apps

1πŸ‘

βœ…

A foreign key represents a one to many relationships. This is used to relate a model instance with several instances of other model (ie. a profile can be related with several pictures).

If you want to have only one hero per town and only one town per hero you need a one to one relationship.

If you want to have many heros in town and many towns per hero you need a many to many relationship.

If you want many heros in a town but only one town per hero or many towns per hero and only one hero per town you need a one to many relationship. Have in mind that the β€œmany” part in the relationship is in the model that holds the ForeignKey Field.

With this you should not need to import models at both sides.

If town is owned by only one hero and hero can have only one town it is a one to one relationships. Check the documentation for reverse relationship. IE. If you put the relationship in hero you can get the hero from town using the reverse.

πŸ‘€cdvv7788

Leave a comment