/usr/share/doc/python3-marshmallow-doc/html/nesting.html is in python3-marshmallow-doc 3.0.0b3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nesting Schemas — marshmallow 3.0.0b3 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '3.0.0b3',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Custom Fields" href="custom_fields.html" />
<link rel="prev" title="Quickstart" href="quickstart.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="nesting-schemas">
<span id="nesting"></span><h1>Nesting Schemas<a class="headerlink" href="#nesting-schemas" title="Permalink to this headline">¶</a></h1>
<p>Schemas can be nested to represent relationships between objects (e.g. foreign key relationships). For example, a <code class="docutils literal"><span class="pre">Blog</span></code> may have an author represented by a User object.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">datetime</span> <span class="kn">as</span> <span class="nn">dt</span>
<span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">email</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">email</span> <span class="o">=</span> <span class="n">email</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="o">=</span> <span class="n">dt</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">friends</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">employer</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">class</span> <span class="nc">Blog</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">,</span> <span class="n">author</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="n">title</span>
<span class="hll"> <span class="bp">self</span><span class="o">.</span><span class="n">author</span> <span class="o">=</span> <span class="n">author</span> <span class="c1"># A User object</span>
</span></pre></div>
</div>
<p>Use a <a class="reference internal" href="api_reference.html#marshmallow.fields.Nested" title="marshmallow.fields.Nested"><code class="xref py py-class docutils literal"><span class="pre">Nested</span></code></a> field to represent the relationship, passing in a nested schema class.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">marshmallow</span> <span class="kn">import</span> <span class="n">Schema</span><span class="p">,</span> <span class="n">fields</span><span class="p">,</span> <span class="n">pprint</span>
<span class="k">class</span> <span class="nc">UserSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">String</span><span class="p">()</span>
<span class="n">email</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Email</span><span class="p">()</span>
<span class="n">created_at</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">DateTime</span><span class="p">()</span>
<span class="k">class</span> <span class="nc">BlogSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">title</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">String</span><span class="p">()</span>
<span class="hll"> <span class="n">author</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="n">UserSchema</span><span class="p">)</span>
</span></pre></div>
</div>
<p>The serialized blog will have the nested user representation.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">"Monty"</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="s2">"monty@python.org"</span><span class="p">)</span>
<span class="n">blog</span> <span class="o">=</span> <span class="n">Blog</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s2">"Something Completely Different"</span><span class="p">,</span> <span class="n">author</span><span class="o">=</span><span class="n">user</span><span class="p">)</span>
<span class="n">result</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">BlogSchema</span><span class="p">()</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">blog</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="c1"># {'title': u'Something Completely Different',</span>
<span class="c1"># {'author': {'name': u'Monty',</span>
<span class="c1"># 'email': u'monty@python.org',</span>
<span class="c1"># 'created_at': '2014-08-17T14:58:57.600623+00:00'}}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If the field is a collection of nested objects, you must set <code class="docutils literal"><span class="pre">many=True</span></code>.</p>
<div class="last highlight-python"><div class="highlight"><pre><span></span><span class="n">collaborators</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="n">UserSchema</span><span class="p">,</span> <span class="n">many</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="specifying-which-fields-to-nest">
<span id="specifying-nested-fields"></span><h2>Specifying Which Fields to Nest<a class="headerlink" href="#specifying-which-fields-to-nest" title="Permalink to this headline">¶</a></h2>
<p>You can explicitly specify which attributes of the nested objects you want to serialize with the <code class="docutils literal"><span class="pre">only</span></code> argument.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">BlogSchema2</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">title</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">String</span><span class="p">()</span>
<span class="hll"> <span class="n">author</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="n">UserSchema</span><span class="p">,</span> <span class="n">only</span><span class="o">=</span><span class="p">[</span><span class="s2">"email"</span><span class="p">])</span>
</span>
<span class="n">schema</span> <span class="o">=</span> <span class="n">BlogSchema2</span><span class="p">()</span>
<span class="n">result</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">blog</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># 'title': u'Something Completely Different',</span>
<span class="c1"># 'author': {'email': u'monty@python.org'}</span>
<span class="c1"># }</span>
</pre></div>
</div>
<p>You can represent the attributes of deeply nested objects using dot delimiters.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">SiteSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">blog</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="n">BlogSchema2</span><span class="p">)</span>
<span class="n">schema</span> <span class="o">=</span> <span class="n">SiteSchema</span><span class="p">(</span><span class="n">only</span><span class="o">=</span><span class="p">[</span><span class="s1">'blog.author.email'</span><span class="p">])</span>
<span class="hll"><span class="n">result</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">schema</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
</span><span class="n">pprint</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># 'blog': {</span>
<span class="c1"># 'author': {'email': u'monty@python.org'}</span>
<span class="c1"># }</span>
<span class="c1"># }</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If you pass in a string field name to <code class="docutils literal"><span class="pre">only</span></code>, only a single value (or flat list of values if <code class="docutils literal"><span class="pre">many=True</span></code>) will be (de)serialized.</p>
<div class="last highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">UserSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">String</span><span class="p">()</span>
<span class="n">email</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Email</span><span class="p">()</span>
<span class="hll"> <span class="n">friends</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="s1">'self'</span><span class="p">,</span> <span class="n">only</span><span class="o">=</span><span class="s1">'name'</span><span class="p">,</span> <span class="n">many</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</span><span class="c1"># ... create ``user`` ...</span>
<span class="n">serialized_data</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">UserSchema</span><span class="p">()</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">serialized_data</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># "name": "Steve",</span>
<span class="c1"># "email": "steve@example.com",</span>
<span class="hll"><span class="c1"># "friends": ["Mike", "Joe"]</span>
</span><span class="c1"># }</span>
<span class="n">deserialized_data</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">UserSchema</span><span class="p">()</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">deserialized_data</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># "name": "Steve",</span>
<span class="c1"># "email": "steve@example.com",</span>
<span class="hll"><span class="c1"># "friends": [{"name": "Mike"}, {"name": "Joe"}]</span>
</span><span class="c1"># }</span>
</pre></div>
</div>
</div>
<p>You can also exclude fields by passing in an <code class="docutils literal"><span class="pre">exclude</span></code> list. This argument also allows representing the attributes of deeply nested objects using dot delimiters.</p>
</div>
<div class="section" id="two-way-nesting">
<span id="id1"></span><h2>Two-way Nesting<a class="headerlink" href="#two-way-nesting" title="Permalink to this headline">¶</a></h2>
<p>If you have two objects that nest each other, you can refer to a nested schema by its class name. This allows you to nest Schemas that have not yet been defined.</p>
<p>For example, a representation of an <code class="docutils literal"><span class="pre">Author</span></code> model might include the books that have a foreign-key (many-to-one) relationship to it. Correspondingly, a representation of a <code class="docutils literal"><span class="pre">Book</span></code> will include its author representation.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">AuthorSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="c1"># Make sure to use the 'only' or 'exclude' params</span>
<span class="c1"># to avoid infinite recursion</span>
<span class="hll"> <span class="n">books</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="s1">'BookSchema'</span><span class="p">,</span> <span class="n">many</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">(</span><span class="s1">'author'</span><span class="p">,</span> <span class="p">))</span>
</span> <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">fields</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="s1">'name'</span><span class="p">,</span> <span class="s1">'books'</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">BookSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">author</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="n">AuthorSchema</span><span class="p">,</span> <span class="n">only</span><span class="o">=</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="s1">'name'</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="n">fields</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="s1">'title'</span><span class="p">,</span> <span class="s1">'author'</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">marshmallow</span> <span class="kn">import</span> <span class="n">pprint</span>
<span class="kn">from</span> <span class="nn">mymodels</span> <span class="kn">import</span> <span class="n">Author</span><span class="p">,</span> <span class="n">Book</span>
<span class="n">author</span> <span class="o">=</span> <span class="n">Author</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'William Faulkner'</span><span class="p">)</span>
<span class="n">book</span> <span class="o">=</span> <span class="n">Book</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s1">'As I Lay Dying'</span><span class="p">,</span> <span class="n">author</span><span class="o">=</span><span class="n">author</span><span class="p">)</span>
<span class="n">book_result</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">BookSchema</span><span class="p">()</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">book</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">book_result</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># "id": 124,</span>
<span class="c1"># "title": "As I Lay Dying",</span>
<span class="c1"># "author": {</span>
<span class="c1"># "id": 8,</span>
<span class="c1"># "name": "William Faulkner"</span>
<span class="c1"># }</span>
<span class="c1"># }</span>
<span class="n">author_result</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">AuthorSchema</span><span class="p">()</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">author</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">author_result</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># "id": 8,</span>
<span class="c1"># "name": "William Faulkner",</span>
<span class="c1"># "books": [</span>
<span class="c1"># {</span>
<span class="c1"># "id": 124,</span>
<span class="c1"># "title": "As I Lay Dying"</span>
<span class="c1"># }</span>
<span class="c1"># ]</span>
<span class="c1"># }</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If you need to, you can also pass the full, module-qualified path to <code class="xref py py-obj docutils literal"><span class="pre">fields.Nested</span></code>.</p>
<div class="last highlight-default"><div class="highlight"><pre><span></span><span class="n">books</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="s1">'path.to.BookSchema'</span><span class="p">,</span>
<span class="n">many</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">(</span><span class="s1">'author'</span><span class="p">,</span> <span class="p">))</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="nesting-a-schema-within-itself">
<span id="self-nesting"></span><h2>Nesting A Schema Within Itself<a class="headerlink" href="#nesting-a-schema-within-itself" title="Permalink to this headline">¶</a></h2>
<p>If the object to be marshalled has a relationship to an object of the same type, you can nest the <code class="xref py py-obj docutils literal"><span class="pre">Schema</span></code> within itself by passing <code class="docutils literal"><span class="pre">"self"</span></code> (with quotes) to the <a class="reference internal" href="api_reference.html#marshmallow.fields.Nested" title="marshmallow.fields.Nested"><code class="xref py py-class docutils literal"><span class="pre">Nested</span></code></a> constructor.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">UserSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">String</span><span class="p">()</span>
<span class="n">email</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Email</span><span class="p">()</span>
<span class="hll"> <span class="n">friends</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="s1">'self'</span><span class="p">,</span> <span class="n">many</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</span> <span class="c1"># Use the 'exclude' argument to avoid infinite recursion</span>
<span class="hll"> <span class="n">employer</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Nested</span><span class="p">(</span><span class="s1">'self'</span><span class="p">,</span> <span class="n">exclude</span><span class="o">=</span><span class="p">(</span><span class="s1">'employer'</span><span class="p">,</span> <span class="p">),</span> <span class="n">default</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span>
</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="s2">"Steve"</span><span class="p">,</span> <span class="s1">'steve@example.com'</span><span class="p">)</span>
<span class="n">user</span><span class="o">.</span><span class="n">friends</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">User</span><span class="p">(</span><span class="s2">"Mike"</span><span class="p">,</span> <span class="s1">'mike@example.com'</span><span class="p">))</span>
<span class="n">user</span><span class="o">.</span><span class="n">friends</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">User</span><span class="p">(</span><span class="s1">'Joe'</span><span class="p">,</span> <span class="s1">'joe@example.com'</span><span class="p">))</span>
<span class="n">user</span><span class="o">.</span><span class="n">employer</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="s1">'Dirk'</span><span class="p">,</span> <span class="s1">'dirk@example.com'</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">UserSchema</span><span class="p">()</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">result</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="c1"># {</span>
<span class="c1"># "name": "Steve",</span>
<span class="c1"># "email": "steve@example.com",</span>
<span class="c1"># "friends": [</span>
<span class="c1"># {</span>
<span class="c1"># "name": "Mike",</span>
<span class="c1"># "email": "mike@example.com",</span>
<span class="c1"># "friends": [],</span>
<span class="c1"># "employer": null</span>
<span class="c1"># },</span>
<span class="c1"># {</span>
<span class="c1"># "name": "Joe",</span>
<span class="c1"># "email": "joe@example.com",</span>
<span class="c1"># "friends": [],</span>
<span class="c1"># "employer": null</span>
<span class="c1"># }</span>
<span class="c1"># ],</span>
<span class="c1"># "employer": {</span>
<span class="c1"># "name": "Dirk",</span>
<span class="c1"># "email": "dirk@example.com",</span>
<span class="c1"># "friends": []</span>
<span class="c1"># }</span>
<span class="c1"># }</span>
</pre></div>
</div>
</div>
<div class="section" id="next-steps">
<h2>Next Steps<a class="headerlink" href="#next-steps" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li>Want to create your own field type? See the <a class="reference internal" href="custom_fields.html#custom-fields"><span class="std std-ref">Custom Fields</span></a> page.</li>
<li>Need to add schema-level validation, post-processing, or error handling behavior? See the <a class="reference internal" href="extending.html#extending"><span class="std std-ref">Extending Schemas</span></a> page.</li>
<li>For example applications using marshmallow, check out the <a class="reference internal" href="examples.html#examples"><span class="std std-ref">Examples</span></a> page.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo">
<a href="index.html">
<img class="logo" src="_static/marshmallow-logo.png" alt="Logo"/>
</a>
</p>
<p class="blurb">Object serialization and deserialization, lightweight and fluffy.</p>
<h3>Useful Links</h3>
<ul>
<li><a href="http://pypi.python.org/pypi/marshmallow">marshmallow @ PyPI</a></li>
<li><a href="http://github.com/marshmallow-code/marshmallow">marshmallow @ GitHub</a></li>
<li><a href="http://github.com/marshmallow-code/marshmallow/issues">Issue Tracker</a></li>
</ul>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Nesting Schemas</a><ul>
<li><a class="reference internal" href="#specifying-which-fields-to-nest">Specifying Which Fields to Nest</a></li>
<li><a class="reference internal" href="#two-way-nesting">Two-way Nesting</a></li>
<li><a class="reference internal" href="#nesting-a-schema-within-itself">Nesting A Schema Within Itself</a></li>
<li><a class="reference internal" href="#next-steps">Next Steps</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="quickstart.html" title="previous chapter">Quickstart</a></li>
<li>Next: <a href="custom_fields.html" title="next chapter">Custom Fields</a></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© 2017 <a href="http://stevenloria.com">Steven Loria</a>.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.5</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.8</a>
</div>
</body>
</html>
|