How to make a Django application plugin?

Say, for example, I have a blog application that I want to use for different projects, but I always want the Blog to be associated with some other model. For example, in one case, I want it to be associated with a user:

site.com/someuser/blog

But on another site, I want it to be associated, say, with a school:

site.com/someschool/blog

Is there a way to make the Blog app plug-in so that there is no need to redefine the model (by adding a foreign key field) when I drop it into the project?

+6
django django-models django-apps
source share
3 answers

You might want to study the ContentTypes structure, I used it to create a comment application that can be used to comment on any model in the database (for various reasons, I did not want to use the standard django comment application).

http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/

+4
source share

There are several important details to enable reuse of the application, and I think it’s best to link the two most important sets of documentation on the topic:

+6
source share

A common relationship allows you to have a foreign key for any other model. However, it is not clear from your question what type of object you want to associate with the foreign key. I suspect that the relationship with the foreign key is not very general - you just did not notice another part of your system, which can also be a reusable application.

+3
source share

All Articles