In this chapter, we will discuss the following topics:
- The importance of models
- Class diagrams
- Model structural patterns
- Model behavioral patterns
- Migrations
In Django, models are classes that provide an object-oriented way of dealing with databases. Typically, each class refers to a database table and each attribute refers to a database column. You can make queries to these tables using an automatically generated API.
Models can be the base for many other components. Once you have a model, you can rapidly derive model admins, model forms, and all kinds of generic views. In each case, you would need to write a line of code or two, just so that it does not seem too magical.
Also, models are used in more places than you would expect. This is because Django can be run in several ways. Some of the entry points of Django are as follows:
- The familiar web request-response flow
- Django interactive shell
- Management commands
- Test scripts
- Asynchronous task queues...