Reader small image

You're reading from  Becoming an Enterprise Django Developer

Product typeBook
Published inJun 2022
Reading LevelIntermediate
PublisherPackt
ISBN-139781801073639
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Michael Dinder
Michael Dinder
author image
Michael Dinder

Michael Dinder works as a senior backend developer at Cart, Inc. Michael has helped to develop projects for large enterprises such as PayPal and other companies such as Corcoran Pacific Properties, and countless more either directly or indirectly. He has been programming for more than 15 years with a number of different languages and frameworks, with a focus on Python/Django for the past 5+ years.
Read more about Michael Dinder

Right arrow

Working with model field relationships

Django provides three relationship types for linking tables:

  • Manytoone
  • Manytomany
  • Onetoone

A many-to-one relationship is defined by using a ForeignKey field, and the other two relationship types are defined using the self-explanatory ManyToManyField and OneToOneField. These fields are named appropriately after the relationship type that they represent.

Next, we will discuss the key components of working with model field relationships.

Field arguments

The three field types, ForeignKey, ManyToManyField, and OneToOneField, all accept the standard default, blank, and verbose_name field arguments that other field types accept. The null argument will have no effect on a ManyToManyField and will only apply to the ForeignKey and OneToOneField types. Two of these field types—ForeignKey and OneToOneField—require at least two positional arguments, the first being...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Becoming an Enterprise Django Developer
Published in: Jun 2022Publisher: PacktISBN-13: 9781801073639

Author (1)

author image
Michael Dinder

Michael Dinder works as a senior backend developer at Cart, Inc. Michael has helped to develop projects for large enterprises such as PayPal and other companies such as Corcoran Pacific Properties, and countless more either directly or indirectly. He has been programming for more than 15 years with a number of different languages and frameworks, with a focus on Python/Django for the past 5+ years.
Read more about Michael Dinder