Snippet 1: Understanding ForeignKey and M2M

Understanding ForeignKey and ManyToManyField in models.Model:

1. ForeignKey declares Many-To-1 relationship

– uses variable to access PrimaryKey

– puts ‘Many’ of itself as ‘set’ to PrimaryKey object

………………………………. \

VolProg (ForeignKey) ——- (PrimaryKey) Ngo

……………………………….. /

2. M2M declares Many-To-Many relationship

– uses variable.all to access all ‘Many’ PrimaryKeys

– puts ‘Many’ of itself as ‘set’ to PrimaryKey objects

………………………………. \ ……… /

VolProg (M2MField) ———- ———-(PrimaryKey) Ngo

……………………………….. / …….. \

Advertisements
This entry was posted in Snippets. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s