Closed rmk135 closed 8 years ago
The idea is to create model.get_data() method that will return model's data as a dict.
model.get_data()
dict
fields.Model
fields.Collection
Note: currently there is model.__data__ derived attribute that should be dropped in favor of model.get_data() method.
model.__data__
Example:
class Photo(models.DomainModel): id = fields.Int() storage_path = fields.String() class Profile(models.DomainModel): id = fields.Int() name = fields.String() main_photo = fields.Model(Photo) photos = fields.Collection(Photo) photo1 = Photo(id=1, storage_path='some/dir/where/photos/live/1.jpg') photo2 = Photo(id=2, storage_path='some/dir/where/photos/live/2.jpg') profile = Profile(id=1, name='John', main_photo=photo1, photos=[photo1, photo2]) assert profile.get_data() == { 'id': 1, 'name': 'John', 'main_photo': {'id': 1, 'storage_path': 'some/dir/where/photos/live/1.jpg'}, 'photos': [ {'id': 1, 'storage_path': 'some/dir/where/photos/live/1.jpg'}, {'id': 2, 'storage_path': 'some/dir/where/photos/live/2.jpg'} ] }
Issue has been released with version #0.0.4 PR #31
The idea is to create
model.get_data()
method that will return model's data as adict
.fields.Model
orfields.Collection
), the data of related models should be returned also.Note: currently there is
model.__data__
derived attribute that should be dropped in favor ofmodel.get_data()
method.Example: