开发者

Django model method: how to refer to itself?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜