0

Say I have some third party application that I want to subclass, lets call it ThirdPartyClass. I want to subclass this to create a genereal user, and then have the flexibility to subclass the general user for more specific ones. It would look something like this:

models.py

class GeneralUser(ThirdPartyClass):
    user = models.OneToOneField(
           settings.AUTH_USER_MODEL)
    # general fields would go here


class SpecificUser(GeneralUser):
    # specific fields would go here

Clearly, this will not work as I want to subclass AbstractUser? Maybe that is not even the correct way to approach this. Is there a solution to this?

Side Note: The third party-application I have in mind can be found here. Regardless, hopefully this answer can be solved without specifics on the third party app, but if there is no other choice, then whatever gets the job done will be acceptable! Thanks!

Joker
  • 2,119
  • 4
  • 27
  • 38
  • I don't understand your question. First of all it is not “clear” that this will not work, as I believe that _inheritance_ in OOP _does_ work. And why did you redefine `user` field in your derived class? – kirelagin Jun 02 '13 at 07:55
  • I did not mean to redefine `user` field in the derived class, edited and fixed that. I know this inheritance model will work, but `AbstractUser` is not subclassed in the example. That is the problem because I want it to register as a django `User`. – Joker Jun 02 '13 at 08:04
  • If `ThirdPartyClass` subclasses `AbstractUser` your class will also implicitly subclass it. If `ThirdPartyClass` does not subclass `AbstractUser`, subclass it explicitly in your class. – kirelagin Jun 02 '13 at 08:06
  • Turns out my example does not subclass `AbstractUser`, but it is abstract class, that is where I was getting thrown off. Thanks for the help. – Joker Jun 02 '13 at 08:11

1 Answers1

0

If ThirdPartyClass subclasses AbstractUser, you are already done.

If if doesn't, subclass it in your own class:

class GeneralUser(ThirdPartyClass, AbstractUser):
    # ...
kirelagin
  • 13,248
  • 2
  • 42
  • 57