On Feb 10, 5:03 am, Almost George <almostgeo...@almostexciting.com> wrote: > On the following example models (actual models, removed of cruft that > doesn't seem to apply) I'd like to add a "get_upcoming_events" method > to Band like the one on Venue, but because of the relationship I'm not > sure how to use the API/filter. (An Event has the same bands, at > possibly different occurrences, whereas each Occurrence happens at a > particular Venue - if the models/structure needed justifying). > > [ code highlighted @ dpaste:http://dpaste.com/118817/] > > class Event(models.Model): > name = models.CharField(max_length=50, unique=True) > bands = models.ManyToManyField(Band) > > class EventOccurrence(models.Model): > name = models.CharField(max_length=50, blank=True) > venue = models.ForeignKey(Venue) > event = models.ForeignKey(Event) > start = models.DateField() > end = models.DateField() > > class Band(models.Model): > admin_approved = models.BooleanField(default=False) > name = models.CharField(max_length=50, unique=True) > > def get_upcoming_events(self): > # How do I get Events, where the EventOccurrence.start is > filtered > # the same as this method on the Venue model? > pass > > class Venue(models.Model): > name = models.CharField(max_length=50) > > def get_upcoming_events(self): > return self.eventoccurrence_set.filter > (start__gte=datetime.today())
Looks like you could just use the same filter as in Venue, just adding 'event' before: self.event.eventoccurence_set.filter(...) -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---