开发者

Design Golf: modeling an Address in appengine, aka an AddressProperty?

Today I was refactoring some code and revisited an old friend, an Address class (see below). It occurred to me that, in our application, we don't do anything special with addresses-- no queries, only lightweight validation and frequent serialization to JSON. The only "useful" properties from the developer point-of-view are the label and person.

So, I considered refactoring the Address model to use a custom AddressProperty (see below), which strikes me as a good thing to do, but off-the-top I don't see any compelling advantages.

Which method would yo开发者_开发问答u choose, why and what tradeoffs guide that decision?

# a lightweight Address for form-based CRUD
# many-to-one relationship with Person objects
class Address(db.Model):
   label=db.StringProperty()
   person=db.ReferenceProperty(collection_name='addresses')
   address1=db.StringProperty()
   address2=db.StringProperty()
   city=db.StringProperty()
   zipcode=db.StringProperty()


# an alternate representation -- worthwhile? tradeoffs?
class Address(db.Model):
   label=db.StringProperty()
   person=db.ReferenceProperty(collection_name='addresses')
   details=AddressProperty()   # like db.PostalAddressProperty, more methods


Given that you don't need to query on addresses, and given they tend to be fairly small (as opposed to, say, a large binary blob), I would suggest going with the latter. It'll save space and time (fetching it) - the only real downside is that you have to implement the property yourself.


If you wanted to be a little different you could always store the data in one table as structures and then have another table for lookups and metadata

Design Golf: modeling an Address in appengine, aka an AddressProperty?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜