-
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1896 from marshmallow-code/ordered_set_default
Use OrderedSet as default set_class
- Loading branch information
Showing
7 changed files
with
35 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,37 +524,6 @@ Note that ``name`` will be automatically formatted as a :class:`String <marshmal | |
# No need to include 'uppername' | ||
additional = ("name", "email", "created_at") | ||
Ordering Output | ||
--------------- | ||
|
||
To maintain field ordering, set the ``ordered`` option to `True`. This will instruct marshmallow to serialize data to a `collections.OrderedDict`. | ||
|
||
.. code-block:: python | ||
from collections import OrderedDict | ||
from pprint import pprint | ||
from marshmallow import Schema, fields | ||
class UserSchema(Schema): | ||
first_name = fields.String() | ||
last_name = fields.String() | ||
email = fields.Email() | ||
class Meta: | ||
ordered = True | ||
u = User("Charlie", "Stones", "[email protected]") | ||
schema = UserSchema() | ||
result = schema.dump(u) | ||
assert isinstance(result, OrderedDict) | ||
pprint(result, indent=2) | ||
# OrderedDict([('first_name', 'Charlie'), | ||
# ('last_name', 'Stones'), | ||
# ('email', '[email protected]')]) | ||
Next Steps | ||
---------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters