0

I use class based views and i need to inherit two form_valids from different views for example.

Class A(FormView)

def form_valid()
Does some stuff
return super().form_valid


Class B(FormView)

def form_valid()
Does some more stuff
return super().form_valid

Class C(Class A, Class B):

def form_valid()
takes form A and B stuff and does some more stuff
return super().form_valid

my Class C is only inheriting from the first form_valid and as this is a large project i'm trying to avoid having to revamp the views i'm inheriting to be able to just do the form stuff in class C.

All suggestions welcome

1 Answers1

0

This is not great practice here. You probably will have to refactor a lot. Don't be afraid to. Your reason for not doing something should not only be time and effort especially if it's at the cost of code quality.

See How does Python's super() work with multiple inheritance? for information on multiple inheritance.

My solution would be to pull the is_valid methods for A and B views out of the views and into utility methods. Then call these in the is_valids for classes A, B and C as needed.

Ian Kirkpatrick
  • 1,861
  • 14
  • 33