Dave
Dave

Reputation: 13

Polymodel on App Engine suggestion

I'm designing a model for a posting system where an entry contains an image with or without a comment. An user can reply to it as either a comment or as an image entry as well.

As there can be more properties for ImageEntry, I came up with this design with Polymodel. Not sure if this is the best way to do this. Storage-wise, is CommentEntry less than ImageEntry?

Any suggestions would be great.

class Entry(polymodel.PolyModel):
  comment    = db.TextProperty()
  reply_to   = db.SelfReferenceProperty() # reference to the entry
  created_at = properties.DateTimeProperty(auto_now_add=True)
  updated_at = properties.DateTimeProperty(auto_now=True)

class CommentEntry(Entry):
  created_by = db.ReferenceProperty(User, collection_name='comment_entries')

class ImageEntry(Entry):
  created_by = db.ReferenceProperty(User, collection_name='image_entries')
  image_url  = db.LinkProperty(indexed=False)
  slug       = db.StringProperty(indexed=False)

Upvotes: 1

Views: 198

Answers (1)

ryan
ryan

Reputation: 2945

this model will work fine, and yes, a CommentEntry will be smaller than an ImageEntry from the same user if the ImageEntry has an image URL and/or slug.

however, i'd make this much simpler by putting created_by, image_url, and slug into Entry and getting rid of CommentEntry and ImageEntry altogether. since the app engine datastore is schemaless, and properties are optional by default, you'll only pay the cost of the image_url and slug properties when you fill them in for image entries.

Upvotes: 1

Related Questions