Subclass a Django Model Form and Add Extra Fields

A common use case of forms is to subclass some type of base form and add a couple extra fields. Take the following base form for example:

The model has a variety of other fields in it so I’m using fields in the Meta class to limit to just these three. Now let’s add a couple fields in a subclass:

As you can see, rather than re-specifying all the fields in the Meta class I am simply adding the new fields to the parent’s existing field list.

2 thoughts on “Subclass a Django Model Form and Add Extra Fields”

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