liveBook · Manning

One-to-one relationship

As explained in Django in Action

A one-to-one relationship is a relationship in which each record on one side corresponds to at most one record on the other side.

A one-to-one relationship links each record on one side to at most one record on the other. In a web application, it is useful when extra data belongs to a user but should remain separate from the user account itself. section 6.2.2

For RiffMates, UserProfile stores account-related data while keeping musician profiles and controlled venues in separate relationships. The UserProfile model points to User with OneToOneField and uses cascade deletion. section 6.2.2

The implementation follows this flow:

  • Expose the profile inside Django Admin with a stacked inline, then create migrations before testing the development server. section 6.2.2

How Django in Action covers it

How deep it goes
Implements the model field, deletion behavior, admin integration, and migration workflow without exploring database internals.
Examples
Uses RiffMates UserProfile, musician profiles, controlled venues, stacked inlines, and the Django Admin user screen.
What it assumes
Assumes familiarity with Django models, User objects, admin.py, and management commands such as makemigrations and migrate.
What you can do after
Apply it via Django ORM and Django Admin to attach one profile model to each user account.
How it connects
Connects user profiles with User objects, many-to-many relationships, Django models, and Django Admin.

Also explained in

Compare how 3 books explain one-to-one relationship →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.