On Feb 10, 1:30 am, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > 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.
That doesn't seem to work. Here's my manage.py shell session, which appears as I expected it to: (hopefully email clients/google won't screw up the quoting, otherwise see http://dpaste.com/118932/ ) >>> from xmx.models import Band >>> b = Band.objects.get(name__startswith='r') >>> b <Band: rod> >>> b.get_upcoming_events <bound method Band.get_upcoming_events of <Band: rod>> >>> b.get_upcoming_events() Traceback (most recent call last): File "<console>", line 1, in <module> File "/xxxx/xxxxx/django_projects/../xmx/models.py", line 39, in get_upcoming_events return self.event.eventoccurrence_set.filter (start__gte=datetime.today()) AttributeError: 'Band' object has no attribute 'event' - Any other suggestions? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---