Creating documents

A new user object as defined in Chapter 2Schema Design and Data Modeling, can be created with a single line:

>>> user = User('[email protected]', 'Alex', 'Giamas').save()

In this example, we used positional arguments in the same order they were defined in the user model to assign values to the user model attributes.

We can also use keyword arguments or a mix of both, like this:

>>> user = User(email='[email protected]', 'Alex', last_name='Giamas').save()

Bulk saving can be done by passing in an array of users to bulk_create():

>>> users = [ user1, user2,...,userN]
>>> User.bulk_create(users)

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.141.115