代码完成 Pydev Django 模型外键字段
Eclipse/pydev 中的代码完成对我来说效果不错。然而,有一件事并不像我想要的那样工作。考虑以下 django 模型:
class ReletionTree(models.Model):
mother = models.ForeignKey('RelationTree', blank=True, null=True)
father = models.ForeignKey('RelationTree', blank=True, null=True)
name = models.CharField()
rt = RelationTree.objects.get(name='Mary') #assume unique on Mary
现在解决问题:
rt. #--> will code complete and give me options mother/father/name
rt.mother. #--> will not code complete into mother/father/name, it will code
# complete as if isinstance(rt.mother, models.ForeignKey) (I think)
有没有办法让 Pydev 明白我希望它编码完整的外键 就好像它们属于它所指向的类型(在上面的情况下是 RelationTree 而不是 models.ForeignKey)
谢谢,David
Code completion in Eclipse/pydev works decent for me. However there is one thing that does not work like I want it to. Consider the following django model:
class ReletionTree(models.Model):
mother = models.ForeignKey('RelationTree', blank=True, null=True)
father = models.ForeignKey('RelationTree', blank=True, null=True)
name = models.CharField()
rt = RelationTree.objects.get(name='Mary') #assume unique on Mary
Now to the problem:
rt. #--> will code complete and give me options mother/father/name
rt.mother. #--> will not code complete into mother/father/name, it will code
# complete as if isinstance(rt.mother, models.ForeignKey) (I think)
Is there a way to make Pydev understand that I want it to code complete Foreign Keys
as if they where of the type to which it points (in above case RelationTree and not models.ForeignKey)
Thanks, David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常怀疑(我也使用 Django 和 Eclipse),因为 Pydev 不够聪明,无法理解 Django 用于将
father = models.ForeignKey()
转换为father 的奇怪元类= RelationTree()
或其他。Python 对于自动完成器来说确实很难解析,而 PyDev 和 PyLint 在元类方面似乎完全放弃了。 (pylint 总是抱怨我的模型类没有
objects
成员!)I doubt it very much (I also do Django and Eclipse), because Pydev isn't smart enough to understand the weird metaclass that Django uses to transform
father = models.ForeignKey()
tofather = RelationTree()
or whatever.Python is really hard for autocompleters to parse, and PyDev and PyLint seem to completely give up when it comes to metaclasses. (pylint always complains that my model classes have no
objects
member!)大约 3 年多后,我的 6 个月项目仍未完成(=。但是我现在知道:
Some 3+ years later and my 6 month project is still not finished (=. However I now know that: