Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm new to django. I'm struggling with relationships. I have 4 apps (app1, app2, app3, app4). App2, 3 and 4 have the same fields. And those fields have to be in app1. How can i write my models? Please help. For example app1 is movies(with title and location), app2 is music(with title and location) and app3 is ballet(with title and location). App1 has to be cinema where we have movies, music performances and ballets.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
184 views
Welcome To Ask or Share your Answers For Others

1 Answer

I am not sure your business model, I presume:

class Cinema:
    movies = models.ManyToManyField('app1.Movie')
    music = models.ManyToManyField('app2.Music')
    etc...

Alternatively, if you want movies to assign to one cinema only:

class Movie:
    cinema = models.ForeignKey('app1.Cinema', related_name='movies')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...