如何从类本身引用类实例
我有一堂“场景”课。从这个课程中我可以有几个选择(0..n)。它们将通过一个简单的句子(字符串)呈现给场景对象的用户。每个选择都必须指向一个场景实例(next_scene)。所以我只需要将这个选择与场景实例 ID 相关联。
我如何在 Django Models 和/或 django model.Admin 中实现它。 类场景示例:
class Scene(model.Models)
title = models.CharField(max_length=30)
description = models.TextField()
choices = # TODO
我尝试了几种解决方案,但总是被阻止。我怀疑我从一开始就没有想到这一点。任何帮助将不胜感激。
史蒂芬
I have a class 'Scene'. From this class I can have several choices (0..n). They will be presented to the User of Scene object with a simple sentence (String). Each of the choices must point to a Scene instance (the next_scene). So I only need to associate this choice with a scene instance Id.
How can I implement that in Django Models, and/or in django model.Admin.
Example of a class Scene :
class Scene(model.Models)
title = models.CharField(max_length=30)
description = models.TextField()
choices = # TODO
I have tried several solutions but get always blocked. I suspect I do not conceive it right from the beginning. Any help would appreciated.
Stéphane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决此类问题的最佳解决方案是ManyToMany 关系。您可以将其设置为相同的模型:
The best solution for such thing is
ManyToMany
relation. You can set it to the same model: