Ben Keating
Ben Keating

Reputation: 8376

Django forms equivalent for Model inheritance?

I have a few forms in my forms.py that include redundant fields (username, email...) Im wondering if there is something similar to Django's Model Inheritance (namely, the abstract base style). It would be nice to cut down on redundancy.

Upvotes: 1

Views: 191

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

Forms are normal Python classes, and can be subclassed like any other class. There's no need to do anything special to make an abstract base class - that's only necessary with models because a normal model class has a database component. A form can be subclassed just as it is, and in fact I do this regularly in projects for precisely the same reason, to cut down on redundancy.

Upvotes: 1

Related Questions