Python 中的前向类声明
我按顺序有两个类:
class A(models):
...
class B(models):
a = models.ManyToManyField(A)
现在我必须将我的模型更改为以下一个:
class A(models):
b = models.ManyToManyField(B)
class B(models):
...
我必须使用向南迁移。我想在 A 类中创建新的多对多字段,迁移数据并从 B 类中删除字段。问题是两者都在同一模型中。所以当我把多对多放入A类时就看不到了。因为B声明在A下面。如何解决这个问题呢?
I have two classes in order:
class A(models):
...
class B(models):
a = models.ManyToManyField(A)
Now I have to change my model to one below:
class A(models):
b = models.ManyToManyField(B)
class B(models):
...
I have to use south migrations. I wanted to create new many to many field in class A, migrate data and delete field from class B. The problem is that both are in same model. So when I put many to many into A class it cannot be seen. Because B declaration is below A. How to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少 SQLAlchemy 允许您使用字符串而不是类。如果 django-orm 也允许的话,请尝试一下。
更新:根据 Django/Python 循环模型参考 正是这样去。
At least SQLAlchemy allows you to use a string instead of a class. Try if django-orm allows that, too.
Update: According to Django/Python Circular model reference that's exactly the way to go.