python - 代码完成 Pydev Django 模型外键字段

标签 python django eclipse autocomplete pydev

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)

谢谢,大卫

最佳答案

我很怀疑(我也做Django和Eclipse),因为Pydev不够聪明,无法理解Django用来将father = models.ForeignKey()转换成father = RelationTree() 或其他。

Python 对自动完成器来说真的很难解析,而 PyDev 和 PyLint 在元类方面似乎完全放弃了。 (pylint 总是提示我的模型类没有 objects 成员!)

关于python - 代码完成 Pydev Django 模型外键字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7617009/

相关文章:

python - 在for语句中,我能够得到预期的结果。但是为什么我用while语句却得不到预期的结果呢?

python - PyDev 中单元测试的初始化?

eclipse - 源代码控制工作区

python - 使用 Python urllib/urllib2 发出 http POST 请求以上传文件

python - 无法获得所需的部分而将其余部分踢出

python - 通过第三方应用程序的 Django 自定义身份验证后端

javascript - jquery ui 自动完成结果不显示在 html 下拉列表中

java - Eclipse 富客户端平台,添加 Textbox 或类似的

Python 美汤 : Target a particular element

Django 保存函数错误 - int() argument must be a string or a number, not 'Template'