Snippet 4: Adding inline to admin for both ForeignKey and ManyToManyField

1. Foreign Key Method: Refer to Tutorial 4 (Part 2)

Note: using this same method for ManyToManyField will cause an error

2. ManyToManyField:

a) Under, create an inline class:
Screen Shot 2013-02-16 at 11.00.38 PM
Note: the class must be created before the admin class.. python compiles from top
Note: ‘vp’ is the variable name of the ManyToManyField in ‘Image’ that links both tables.. see the Image Class to understand:
Note: you must include ‘through’.. it tells django to use the table – that links VolProg and Image tables together – as a model to construct the inline class

Screen Shot 2013-02-16 at 11.03.54 PM
Screen Shot 2013-02-16 at 11.04.42 PM

b) of course, don’t forget the basics to import the admin, models, and register the admin
Screen Shot 2013-02-16 at 11.00.50 PM

Screen Shot 2013-02-16 at 11.00.57 PM

Here’s how it looks like:
Screen Shot 2013-02-16 at 11.42.52 PM

if you still don’t get this brief example, try this stackoverflow link

This entry was posted in Snippets. Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s