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

发布于 2024-12-07 22:19:25 字数 762 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断舍离 2024-12-14 22:19:26

我非常怀疑(我也使用 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() to father = 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!)

十六岁半 2024-12-14 22:19:26

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

  1. 您应该使用 pycharm而不是eclipse+pyDev。我认为他们的免费版本更适合python开发。Pycharm
  2. 专业版还支持django代码补全。它节省了我一个很多时间。

Some 3+ years later and my 6 month project is still not finished (=. However I now know that:

  1. You should use pycharm instead of eclipse+pyDev. Their free edition is a much better for python development in my opinion.
  2. Pycharm professional edition also supports django code completion. It saves me a lot of time.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文