Created
April 27, 2011 16:25
-
-
Save kevpie/944602 to your computer and use it in GitHub Desktop.
Simple Model to Domain object creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_object(model, obj): | |
for name, property in model.properties().iteritems(): | |
setattr(obj, name, property.get_value_for_datastore(model)) | |
def to_object(model): | |
def __eq__(self, other): | |
return self.__dict__ == other.__dict__ | |
def __cmp__(self, other): | |
return cmp(self.__dict__, other.__dict__) | |
DomainType = type(model.kind(), (object,), dict(__eq__=__eq__, __cmp__=__cmp__)) | |
obj = DomainType() | |
update_object(model, obj) | |
return obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment