You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/attributes.rst
+52-4Lines changed: 52 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -116,19 +116,67 @@ List Attributes
116
116
---------------
117
117
118
118
DynamoDB list attributes are simply lists of other attributes. DynamoDB asserts no requirements about the types embedded within the list.
119
-
DynamoDB is perfectly content with a list of ``UnicodeAttribute`` and ``NumberAttributes`` mixed together. Pynamo can provide type safety if it is required.
120
-
When defining your model use the ``of=`` kwarg and pass in a class. Pynamo will check that all items in the list are of the type you require.
119
+
Creating an untyped list is done like so:
121
120
122
121
.. code-block:: python
123
122
124
123
from pynamodb.attributes import ListAttribute, NumberAttribute, UnicodeAttribute
125
124
125
+
classGroceryList(Model):
126
+
classMeta:
127
+
table_name ='GroceryListModel'
128
+
129
+
store_name = UnicodeAttribute(hash_key=True)
130
+
groceries = ListAttribute()
131
+
132
+
# Example usage:
133
+
134
+
GroceryList(store_name='Haight Street Market',
135
+
groceries=['bread', 1, 'butter', 6, 'milk', 1])
136
+
137
+
PynamoDB can provide type safety if it is required. Currently PynamoDB does not allow type checks on anything other than ``MapAttribute`` and subclasses of ``MapAttribute``. We're working on adding more generic type checking in a future version.
138
+
When defining your model use the ``of=`` kwarg and pass in a class. PynamoDB will check that all items in the list are of the type you require.
139
+
140
+
.. code-block:: python
141
+
142
+
from pynamodb.attributes import ListAttribute, NumberAttribute
0 commit comments