Simple approach for this is to use try catch block to create proper
field like this:

from django.db import models

try:
        from photos.models import Photo
        photo_field = models.ManyToManyField(Photo)
except ImportError:
        photo_field = None


class Standalone(models.Model):
        name = models.CharField(max_length=5)
        photos = photo_field


This way it is possible to look for a few common apps and add proper
fields. This will work nicely if you know what apps you are going to
install and after installation you run ./manage.py syncdb, but if you
need to add photos app _after_ the installation of Standalone model
things get little bit tricky as you have to create additional table
for that new m2m field (probably handled by schema migration app like
South)

I think this is pretty common problem in terms of portable/reusable
apps but as far as I know there are no solutions/guidelines for it.
For that reason I personally don't like Pinax as it's no more about
reusable apps, it's just collection of apps.

Solution I'm thinking about is something like application repository
with lots of guidelines how to write portable apps and solve
dependency issues etc.


On Aug 23, 1:36 am, "Chris H." <chris.hasenpf...@gmail.com> wrote:
> So I'm trying to get my head around making my small, tightly focused
> apps reusable.  I've done this, but right now still have
> "dependencies" between one another, that I'd like to remove.  For
> simplicity sake, I have an Articles, Events, and Photos app.
>
> Right now each Article has a photos.photo and events.event foreign key
> relationship and each event has a photos.photo_set fk relationship.
> Thus, as currently written all three apps are required.  I'd like to
> rework this such that the installation of each application is not
> required, and I'd think that additional functionality should live in
> the newer app.
>
> That is, when Photos gets "installed" it looks for Articles, if that
> is installed it hooks into the Photos model to supply the photo
> relationship.  And if Events is installed, it'll provide the photoset
> relationship.  If neither is installed, that's okay too, it just
> provides it's base functionality.  When Events gets installed, it
> looks for Articles, and if so allows you to relate an article to an
> event.
>
> Surely, this has done before, right?  Or am I approaching it wrong?
> My google foo fails me...what do I need to be searching for??

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to