liveBook · Manning

Data model

As explained in Build Python Web Apps with Streamlit

A data model is a structured representation of an application's entities, attributes, relationships, and storage organization.

A data model turns an application's needs into an organized plan for storing information. For a haiku app, identify users and haikus, then describe each entity's attributes and relationships: usernames, passwords, haiku text, authors, numeric IDs, and creation times. section 8.2.2

Figure 8.3 Entity-relationship (ER) diagram showing User and Haiku entities with their attributes

Use the entity-relationship diagram to see the User and Haiku entities, their attributes, and the relationship between them before designing tables. section 8.2.2

Translate the model into a relational database schema:

  • Turn entities into tables, such as users and haikus. section 8.2.2
  • Turn attributes into columns, with a primary key uniquely identifying each row. section 8.2.2
  • Represent a one-to-many relationship with a foreign key; the haikus.author column points to users.username. section 8.2.2

A small haiku-app schema

The users table stores one row per user, with username as its primary key. The haikus table stores one row per haiku, with haiku_id as its primary key and author as a foreign key referencing users.username. This structure supports creating, reading, updating, and deleting records. section 8.2.2 section 8.7

Figure 8.4 Database schema with a foreign key relationship between the users and haikus tables

Use the database schema diagram to connect the conceptual entities with concrete tables, columns, primary keys, and the foreign-key relationship. section 8.2.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains ER diagrams and table conversion, including primary and foreign keys, without detailing more complex real-world models.
Examples
Uses users and haikus with usernames, haiku text, authors, numeric IDs, creation times, and a foreign-key relationship.
What you can do after
Apply data modeling to design tables and relationships for CRUD applications using relational databases such as PostgreSQL.
How it connects
Connects entities, attributes, relationships, ER diagrams, relational databases, schemas, primary keys, foreign keys, CRUD, and SQL.

Also explained in

Compare how 23 books explain data model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.