Subscribed unsubscribe Subscribe Subscribe

Django で定義前のモデルを参照する場合について

文字列にすれば OK

class Car(models.Model):
    manufacturer = models.ForeignKey('Manufacturer')
    # ...

class Manufacturer(models.Model):
    # ...

Does Python have class prototypes (or forward declarations)? - Stack Overflow
 

自分自身を参照(自己参照)させたい場合は

class Car(models.Model):
    related_car = models.ForeignKey('self')
    # ...

[Django-users] Self referencing models initialization - Grokbase





Remove all ads