App Engine: how would you... snapshotting entities

Posted by Andrew B. on Stack Overflow See other posts from Stack Overflow or by Andrew B.
Published on 2010-06-11T03:55:49Z Indexed on 2010/06/11 4:03 UTC
Read the original article Hit count: 216

Let's say you have two kinds, Message and Contact, related by a db.ListProperty of keys on Message. A user creates a message, adds some contacts as recipients, and emails the message. Later, the user deletes one of the contact entities that was a recipient of the message. Our application should delete the appropriate Contact entity, but we want to preserve the original recipient list for the message that was sent for the user's records. In essence, we want a snapshot of the message entity at the time it was sent. If we naively delete the contact entity, though, we lose snapshot integrity; if not, we are left with an invalid key.

How would you handle this situation, either in controller logic or model changes?


    class User(db.Model):
        email = db.EmailProperty(required=True)

    class Contact(db.Model): 
        email = db.EmailProperty(required=True) 
        user = db.ReferenceProperty(User, collection_name='contacts') 

    class Message(db.Model): 
        recipients = db.ListProperty(db.Key)   # contacts 
        sender = db.ReferenceProperty(User, collection_name='messages') 
        body = db.TextProperty() 
        is_emailed = db.BooleanProperty(default=False)

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about model