decoupling django apps - best practice to layout a project
I'm working on a project that has sever开发者_StackOverflowal apps, and want to include a news app for news stories.
However, I'd like to link news stories to objects in my custom app, but use an open source news app to run the news.
At the moment I've simply hacked the chosen news app to add in a ForeignKey relationship with my model.
i.e. a widgets app, with a widget model
then a news app with the entry model linked directly to my widget model
Is there a better way to do this? because if I want to update the news app with the latest version of it, it'll obviously overwrite my hack.
I could have the link from my custom model, but the workflow should really be
- Add news article
- choose a widget to link it to
NOT
- Add a news article, save
- Find the widget to link it to
- Link back to the news article
I think you could have a model which inherits from the model in the external app. Something along the lines of:
MyNewsArticle(ExternalAppNewsArticle):
object = models.ForeignKey(MyObject)
As long as you're adding things rather than dropping things, this should work. You have to be careful if the model from the external app has any Custom Managers declared though, because by default Django will not inherit them. You might need to declare them again in your own model.
精彩评论