> 
>> My workaround right now is to have my Model create a helper object and use 
>> manual delegation patterns to get the calls done.  It's kind of gross.  Is 
>> there a pythony way that would allow my model to present itself as a tzinfo, 
>> without using multiple inheritance?  I don't mind having the delegate inside 
>> my model, but I'd rather not have to have all my callers get the delegate 
>> through an extra call (or, in principle, even know about the delegate).
> 
> I'm not fully following your use case, but perhaps it could be done
> the other way around? I.e. create a subclass of tzinfo that has a
> reference to a Model instance?

The OO model that I was trying to use was that the "Region" model simply 
exposed the tzinfo interface, so that anywhere I needed a tzinfo, I could just 
pass the Region.  Since I can't use multiple inheritance with Model safely, I 
don't think there is really any way to do what I wanted.

So now I'm tidying up the two-object approach, and I have a quick question.  Is 
this the right way to initialize my helper object?

class RegionZone(datetime.tzinfo):
  def __init__(self, region):
    self.region = region
  def utcoffset(self, dt):
    return self.region.utcoffset(dt)
  def tzname(self, dt):
    return self.region.tzname(dt)
  def dst(self, dt):
    return self.region.dst(dt)

class RegionModel(db.Model):
  name = db.StringProperty()
  …other properties…

  def __init__(self, *args, **kw):
    self.tz = RegionZone(self)
    db.Model.__init__(self, *args, **kw)

This code works.  I just wanted to make sure that this is the right (safe) way 
to use __init__ on a db.Model.

-Joshua

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to