【问题标题】:Code completion Pydev Django Model Foreign Key Field代码完成 Pydev Django 模型外键字段
【发布时间】:2011-11-28 20:12:34
【问题描述】:

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)

谢谢,大卫

【问题讨论】:

    标签: python django eclipse autocomplete pydev


    【解决方案1】:

    我非常怀疑(我也使用 Django 和 Eclipse),因为 Pydev 不够聪明,无法理解 Django 用来将 father = models.ForeignKey() 转换为 father = RelationTree() 或其他任何东西的奇怪元类。

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

    【讨论】:

      【解决方案2】:

      大约 3 年多后,我 6 个月的项目仍未完成(=。但我现在知道:

      1. 您应该使用 pycharm 而不是 eclipse+pyDev。在我看来,他们的免费版本对于 python 开发来说要好得多。
      2. Pycharm专业版还支持django代码补全。它为我节省了很多时间。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-07
        • 2014-12-06
        • 2020-06-30
        • 2021-09-13
        • 2015-10-14
        • 1970-01-01
        • 1970-01-01
        • 2016-04-24
        相关资源
        最近更新 更多