Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Forms Forms Creating a Form

Haydar Al-Rikabi
Haydar Al-Rikabi
5,971 Points

All form classes (including ModelForm) are subclasses of django.forms.Form?

In the Django docs, I've read the following statement:

All form classes are created as subclasses of django.forms.Form, including the ModelForm, which you encounter in Django’s admin.

I need you to explain to me please how ModelForm is a subclass of django.forms.Form!!!

The reason of my question is that I couldn't verify the docs statement through the Django project on Github. This is what I found there:

  • in /django/forms/models.py the class ModelForm is subclass of BaseModelForm which is also a subclass of BaseForm (located in /django/forms/forms.py).
  • in /django/forms/forms.py the class Form is a subclass of BaseForm.

So, as you can see, both django.forms.Form and django.forms.ModelForm are subclasses of BaseForm, but ModelForm is not a subclass of Form as the docs state.

Is it a mistake in the docs or am I missing something here?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

I agree the documentation appears to be incorrect. Nice catch! You may wish to submit it to Django as a documentation bug!