views:

14

answers:

2

assume the following:

class events(db.model):
  eventDate = db.DateProperty()
  eventItem = db.ReferenceProperty(items)

class items(db.model):
  itemCode = db.IntegerProperty()
  itemTitle = db.StringProperty()

now if i have multiple events in the future for a specific item, how can i show a list of all items with only the next occurring event shown for each item?

i have tried an aggregate field in the item class as:

  itemNext = db.DateProperty()

which gets updated when an event is set but the problem with this is what happens when an event is changed or deleted lots more calls have to be made to empty it or change it (unless i am missing something)

+1  A: 

Is it the case that the next event is the event who's date is in the future and of those dates in the future is closest to right now? If so, I would do something like this:

def get_next(for_item):
    next_event = events.all().filter('eventItem = ', for_item.key()).filter('eventDate >', datetime.datetime.now()).order('eventDate').get()

    return next_event
Adam Crossland
i like this, however, imagine i have 50 items, some with forthcoming events and some not. would i have to make this call 50 times?
khany
A: 

Your best option is to keep a reference to the next event, and do a datastore lookup for it. Yes, that will require updating those records when an associated item is modified or deleted.

Nick Johnson