Skip to content

Add support of nested paths #12

Description

@grundic

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:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from simplemodels.fields import CharField, IntegerField
from simplemodels.models import Document


class User(Document):
    name = CharField()
    salary = IntegerField()


data = {
    'name': 'John Smith',
    'data': {
        'salary': 100500
    }
}


if __name__ == '__main__':
    user = User.create(data)
    print(user)

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:

class User(Document):
    name = CharField()
    salary = IntegerField(nested=['data'])

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions