0

I guess it is a "normal" problem. I want to connect model C with different Models A,B,..

Model A "buildings"
 - time_built
 - description
 - adress
 - architects[]=Model C
 - places

Model B "photos":
 - time_taken
 - title
 - architects[]=Model C
 - places

Model C "architects"
- title
- time_born
- website
- items[]=Model A+Model B

So items should be connected m:n to Model A or B for querying like "find architects by buildings in California". Model A and B can have multiple architects.

Is it possible to realize something like this in Django? I thought to use a Intermediate Model, but as I understood it does not help me too.

rokdd
  • 541
  • 4
  • 14

2 Answers2

0

Yes, Django has Many-to-many relationships.

In Buildings, put

    architects = models.ManyToManyField(Architect)

In Photos, put

    architects = models.ManyToManyField(Architect)

This will handle the relationship and by creation the migration file and running it, the DB tables will be created automatically (they should be 5).

Horatiu Jeflea
  • 7,256
  • 6
  • 38
  • 67
0

Ok seems that there are two solutions:

rokdd
  • 541
  • 4
  • 14