12.4.1 Structuring and Storing Data in Models

A Django model is a Python class that communicates with a database. We structure the data in the model using Django fields, which are Python classes that contain discrete pieces of data. When represented in the database, a model is a table and fields are columns in the table. A model instance is a row of data in the database.

Django fields map to different kinds of column types. A CharField maps to a SQLite3 varchar column, while a DateField maps to a SQLite3 date columns. Django additionally knows how to map fields to PostgreSQL, Oracle, and MySQL databases.

When structuring data in Django, the goal is to start by building models and to let Django generate the database using this data. In no way ...

Get Django Unleashed 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.