where we have to use ‘through’ in django many-to-many model field?

where we have to use ‘through’ in django many-to-many model field?

In django the many-to-many field used to have multiple relationships with referred and used models

In generally, if you use many-to-many field django automatically creates a intermediate table

suppose, for your mighty usecase, you want to add some additional fields in that intermediate table

you can go proceed with the ‘through‘ feature

Image

refer-doc link https://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany

In the above attached image, the Membership class contains the additional fields like date_joined,invite_reason available as I explained above

Without using this special feature, if you do the adding extra fields(date_joined,invite_reason) in the Group class itself,

you can have the field for the each group object like

group([person1,person2,person3,etc..],date_joined,invite_reason)

but not like this

group([person1,date_joined,invite_reason],[person2,date_joined,invite_reason],

[person3,date_joined,invite_reason]…

etc…)

To obtain this usecase we have to go with ‘through‘ attribute feature as availble in the diagram

Advertisements

About Navaneethan

mixed feelings...
This entry was posted in Academic, Django and tagged , , . 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s