Hello Javier, thanks for your answer! The reason for one Event having multiple EventDates is simple: an event like a theatre can have multiple shows/screenings.
Is there a way to add an index on event+date other than unique-together? ( http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together) I cannot use unique-together because that is not the case. EventDates have more than just those two fields (see the full model below) and one event can possibly have multiple shows each day. class EventDate(models.Model): > event = models.ForeignKey(Event) > > date = models.DateField(verbose_name=_(u"start date"), db_index=True) > enddate = models.DateField(verbose_name=_(u"end date"), > blank=True, null=True) > start = models.TimeField(verbose_name=_(u"start time"), > blank=True, null=True) > end = models.TimeField(verbose_name=_(u"end time"), > blank=True, null=True) > > class Meta: > verbose_name = _(u"event date") > verbose_name_plural = _(u"event dates") > ordering = ('event', 'date') > Regards, Fabian 2011/3/28 Javier Guerra Giraldez <jav...@guerrag.com> > On Mon, Mar 28, 2011 at 7:52 AM, Fabian Büchler > <fabian.buech...@gmail.com> wrote: > > > > Events have an EventOnlineManager with a "to_expire" method which should > select all Events with status=online and EventDates associated which date < > today. > > > >> class EventOnlineManager(models.Manager): > >> > >> def get_query_set(self): > >> return (super(EventOnlineManager, self).get_query_set() > >> .filter(status=Event.STATUS_ONLINE)) > >> > >> @property > >> def to_expire(self): > >> today = datetime.date.today() > >> return > (self.annotate(eventdate_max=models.Max('eventdate__date')) > >> .filter(eventdate_max__lt=today)) > > > > I guess you have reasons to allow several EventDates per Event (if > not, they should be a single table). my first attempt would be to > add an (event, date) index to EventDate. can you add an > ordering=('event','date') ? > > -- > Javier > -- 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.