Creating our model

At first, our models.py has only one entity in the database. This entity is News. The structure is very simple and can, clearly, be incremented. This is a good tip: start simple, make tests, and write code that will really be used. The News class is the one that represents the central point of the domain of our application.

First, we declare the imports, as follows:

import datetimefrom flask_mongoengine import MongoEngine

After that, we declare an instance of MongoEngine, which is the tool that we use to give structure to the data coming from MongoDB:

db = MongoEngine()

Now, we will declare the class News itself with the fields that match the representation of the entity. The class is very simple and the fields are completely ...

Get Microservice Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.