-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of nested paths #12
Comments
Might be a good feature. I will ponder about design of this. No promises so far, but pull requests most welcome UPD: |
But what if the field is not a dictionary? It could be list of fields or other document, just nested deeper in the tree. from simplemodels.fields import CharField, ListField, DocumentField
from simplemodels.models import Document
class Comment(Document):
body = CharField()
class User(Document):
class _Data(Document):
comments = ListField([Comment])
name = CharField()
data = DocumentField(_Data)
data = {
'name': 'John Smith',
'data': {
'comments': [
{'body': 'comment #1'},
{'body': 'seconds comment'},
{'body': 'one more comment'},
]
}
}
if __name__ == '__main__':
user = User.create(data)
print(user.name)
for comment in user.data.comments:
print(comment) But there other reasons, why I would prefer to have it described like this: from simplemodels.fields import CharField, ListField, DocumentField
from simplemodels.models import Document
class Comment(Document):
body = CharField()
class User(Document):
name = CharField()
comments = ListField([Comment], nested=['data']) |
ok, now I see your point |
Add tests for `_get_path`.
Add comments.
Add support for DocumentField within nested path.
This is related to incorrectly created #7.
Can you add possibility to specify field disposition in case it's not at root level? Here is small example:
I would like to be able to specify in User model that the salary is nested under data path. And it should be possible to specify nested path. List of strings or usual uri should work fine:
There one things to consider, though: should the configuration count the field itself, or only the nested path: ['data'] vs ['data', 'salary']. The latte less obvious, but let rename fields. But I would say that for that behaviour there should be another configuration option.
The text was updated successfully, but these errors were encountered: