开发者

Django model method: how to refer to itself?

开发者 https://www.devze.com 2023-02-25 05:26 出处:网络
class A(models.Model): name = models.CharField(max_length开发者_运维百科=255) def gen(self): return AnotherClass(self)# Here I want to pass the class A instance
class A(models.Model):
    name = models.CharField(max_length开发者_运维百科=255)

    def gen(self):
        return AnotherClass(self)  # Here I want to pass the class A instance

Is this the write way to do ?


The first named argument in a normal method is passed the instance the method was called on. So, yes.

0

精彩评论

暂无评论...
验证码 换一张
取 消