I have the following two Django Classes MyClassA
and MyClassB
.
MyClassB
has a foreign key reference to an instance of MyClassA
.
from django.db import models
class MyClassA(models.Model):
name = models.CharField(max_length=50, null=False)
@classmethod
def my_method_a(cls):
# What do I put here to call MyClassB.my_method_b()??
class MyClassB(models.Model):
name = models.CharField(max_length=50, null=False)
my_class_a = models.ForeignKey(MyClassA, related_name="MyClassB_my_class_a")
@staticmethod
def my_method_b():
return "Hello"
From within MyClassA
's class method my_method_a
, I would like to call MyClassB
's static method my_method_b
. How can I do it? If my_method_a
was an instance method, I would simply do self.MyClassB_my_class_a.model.my_method_b()
. But since I don't have an instance of MyClassA
, I don't know how to do it.
Can I use cls
instead of self
?