Basic model

Model is a class that describes any json object structure.

For example, we have such "User" json object

{
  "id": 1,
  "username": "some",
  "email": "other"
}

Let's create model for that object

from models_manager import Model, Field


class User(Model):
    id = Field(default=1, json='id')
    username = Field(default='some', json='username')
    email = Field(default='other', json='email')

What we actually did:

  • created an abstraction of the user model
  • described the names of the fields in the user model
  • added values to user model fields

Now we can use this model in our auto tests project, for example to get json

from models_manager import Model, Field


class User(Model):
    id = Field(default=1, json='id')
    username = Field(default='some', json='username')
    email = Field(default='other', json='email')

User.manager.to_json

{
  "id": 1,
  "username": "some",
  "email": "other"
}