How do you make a Django app pluggable?
Asked Answered
H

3

6

Say for example I have a Blog app that I want to be able to drop into different projects, but I always want the Blog to be associated with some other model. For example, in one case I may want it to be associated with a user:

site.com/someuser/blog

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

site.com/someschool/blog

Is there a way to make the Blog app pluggable so that it's not necessary to redefine the model (adding a foreign key field) whenever I drop it into a project?

Helsinki answered 4/5, 2009 at 5:25 Comment(1)
check last django conference for talk on pluggable appsFaggot
A
4

You might want to look into the ContentTypes framework, I used it to create a comment app that can be used for commenting any model in the database (for different reasons, I didn't want to use the standard django comment app).

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

Andeee answered 4/5, 2009 at 15:39 Comment(0)
T
6

There are several important details for making sure an app can be reusable and I think it's best to link to two of the more important sets of documentation on the topic:

Thanks answered 4/5, 2009 at 6:14 Comment(0)
A
4

You might want to look into the ContentTypes framework, I used it to create a comment app that can be used for commenting any model in the database (for different reasons, I didn't want to use the standard django comment app).

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

Andeee answered 4/5, 2009 at 15:39 Comment(0)
B
3

Generic relationships allow you to have a foreign key to any other model. However it's not clear from your question what type of object you want a foreign key to link to. I suspect that foreign key relationship isn't really generic - you just haven't spotted another part of your system that could also be a reusable app.

Beaux answered 4/5, 2009 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.