Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Create

To create a new document, just create a new instance of the class and call the save method, as follows:

>>> post = Post()
>>> post.title = "Post From The Console"
>>> post.text = "Lorem Ipsum..."
>>> post.save()

Otherwise, the values can be passed as keywords in the object creation, as follows:

>>> post = Post(title="Post From Console", text="Lorem Ipsum...")

Unlike SQLAlchemy, MongoEngine does not automatically save related objects that are stored in ReferenceFields. To save any changes to referenced documents along with the changes to the current document, pass cascade as True, as shown in the following code:

>>> post.save(cascade=True)

If you wish to insert a document and skip its checks against the defined parameters in the class ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content