[Answer]-Django Form Views: Should I inherit or use instance of a class

1👍

That Depends on What Kind of Usage you see for MyViewStorage now and in Future.

A. If you know that MyViewStorage will only be used in views like MyView1 and MyView2 and nowhere else. Then it makes a lot of sense that you transfer all common code, present in MyView1 and MyView2 related to storage, in MyViewStorage itself and inherit from it.

PS: You must know how multiple inheritance work in Python, It prioritizes the attributes from left to right in Parent classes (i.e if left most class has the required attribute then it is picked)

B. If you think that MyViewStorage class should be a generic one or can have a lot of extra functionality, which can be used anywhere and can be changed from time to time to make it more generic, then it makes sense to create an instance and use it (because you won’t want un-neccessary attributes in your Views which are not useful to you)

Hope this helps

Leave a comment