I am documenting a Django Project that deals with objects Store, Person, Transaction, and Address
I would appreciate you reading the thing just as sanity check to me but my real question is in the last paragraph.
Only Showing The Fields Which Are a Relation
Store
# The intention here is for each Store to have exactly 1 address that can not be shared with another Store.
# I represent this on my diagram as 1-to-1 Store --> Address
address = models.OneToOneField(Address, on_delete=models.PROTECT)
Person
# The intention here is for each Person (used for Employee and Customers) to have exactly 1 address that can not be shared with another Person.
# I represent this on my diagram as 1-to-1 Person --> Address
address = models.OneToOneField(Address, on_delete=models.PROTECT)
# The intention here is for many Persons to be associated with a Store.
# In this case the association would mean they were an employee of the Store.
# There is a dummpy Store that all customers are associated with (I know not the best design)
# I am represting this relationship as Many-to-1 Person --> Store
store = models.ForeignKey(Store, on_delete=models.PROTECT)
Address
# No relation fields
Transaction
# The intention here is for each Transaction exactly 1 Store that can not be shared with another Store.
# I represent this on my diagram as Many-to-1 Transaction --> Store
store = models.ForeignKey(Store, on_delete=models.PROTECT)
# Here is where it gets confusing to me. A Person(Customer) can have
# Many transactions with a Store but each Transaction only has 1 Person.
#So would this be a Many-to-1 or a Many-to-Many relation Transaction --> Person?
# The way it is defined currently works correctly. I am mostly asking about this conceptually.
person = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
The definition is valid for Transaction -> Person relation. Just think another way to understand. When you filter Transaction model with person_id, you will get the records (which may be multiple) belongs to that person. So there is nothing to change in definition. In the django docs, you can find message "To define a many-to-one relationship, use ForeignKey" in Many-To-One Relationships section.