Howdy folks --

Feels kinda weird to ask a question on this list, but I'm a little  
stumped.

I'm working on converting Ellington into the magic-removal-style  
syntax, and I've been running into an interesting situation with  
"optional" relationships.  An example might illustrate this best::

        class Place(meta.Model):

                def get_event_times(self):
                        "Return a list of EventTime objects"

        -----

        class Event(meta.Model):
                place = meta.ForeignKey(Event)
                ...

        class EventTime(meta.Model):
                event = meta.ForeignKey(Event)
                date = meta.DateTimeField()

The idea is that the Place API should make it easy to get a list of  
EventTimes.  The problem is, however, that a given site might have  
the places app installed, but not the events app.  Having methods  
like ``get_event_times`` effectively couples Places to Events, which  
is lame.

What I've been doing is replacing the ``get_event_times`` method with  
a manager method on Event, so you could do something like::

        place_object.event_set.all_event_times()

I *really* like this idiom; it feels very natural.

However, the problem is that this also works::

        Place.objects.all_event_times()

but returns essentially useless data.

So what I'm getting to is that I'd like to be able to define manager  
methods that are *only* callable in a related context -- actually,  
only in a specific related context.

I've thought about patching the related object descriptors in  
django.db.models.fields.related to add flags onto the dynamically  
created RelatedManager objects to indicate the related context, but  
that would lead to code like::

        class EventManager(Manager):
                def all_event_times(self):
                        if self.related_context == whatever:
                                ...

Which feels un-polymorphic to me.

Am I missing something that's already possible? Or is there a better  
way to handle this?

Jacob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to