How to simulate a schema for a list of built-in dictionaires on python eve

I have a document in which the user has two addresses, for example below. How to create a schema for this in python-eve?

Also, how do I create an API request to allow the user to update only zipcode. Do they need to rewrite the entire document?

{
   _id: "joe",
   name: "Joe Bookreader",
   addresses: [
                {
                  street: "123 Fake Street",
                  city: "Faketon",
                  state: "MA",
                  zip: "12345"
                },
                {
                  street: "1 Some Other Street",
                  city: "Boston",
                  state: "MA",
                  zip: "12345"
                }
              ]
 }
+4
source share
1 answer

As for the schema, this should do the trick ( docs ):

'addresses': {
    'type': 'list',
    'schema' {
        'type': 'dict',
        'schema': {
            'street': {'type': 'string'},
            'city': {'type': 'string'},
            'state': {'type': 'string'},
            'zip': {'type': 'string'}
         }
     }
 }

Dot notation is supported for PATCH requests (update), but not in document lists. They are harder and harder to do in a RESTful way. There, open a ticket for this right now, but not a direct decision, I'm afraid.

+4
source

Source: https://habr.com/ru/post/1627599/


All Articles