About Overriding Class Methods in Python
In Python, you cannot directly override class methods with super()
, but you can do this instead:
class Simple(object):
@classmethod
def get_feature_name(cls):
return "The Feature"
class Magical(Simple):
@classmethod
def get_feature_name(cls):
value = Simple.get_feature_name()
return f"✨✨✨ {value} ✨✨✨"
print(Simple.get_feature_name())
print(Magical.get_feature_name())
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You