V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dicc
V2EX  ›  Python

如何编写代码才能实现这种关联

  •  
  •   dicc · 2022-04-08 20:32:27 +08:00 · 2463 次点击
    这是一个创建于 720 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如有 django model 类

    
    	class Table(models.Model):
    		mgr = models.ForeignKey(to=Manager, ..
            
    

    有 Table 类对象 tab ,我们在调用 tab 的 mgr 属性时
    Pycharm 能够提示出 tab.mgr_id ,请问这种提示是怎么做到的?
    是因为ForeignKey中实现了什么方法吗,还是 Pycharm 专门针对 django 做了优化提示呢

    3 条回复    2022-04-10 10:01:45 +08:00
    Zhuzhuchenyan
        1
    Zhuzhuchenyan  
       2022-04-08 21:05:12 +08:00   ❤️ 1
    Pycharm 应该专门做了很多 Django 的优化,根据官网 https://www.jetbrains.com/help/pycharm/django-support7.html#django-support

    Django support in PyCharm includes:
    ...
    - Code insight support for Django ORM.
    ...
    zhanlanhuizhang
        2
    zhanlanhuizhang  
       2022-04-08 21:56:14 +08:00
    语义分析
    Sailwww
        3
    Sailwww  
       2022-04-10 10:01:45 +08:00
    这个支持可能是通过 https://github.com/JetBrains/python-skeletons ( deprecated )和 https://github.com/python/typeshed 实现的,没具体研究过
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5023 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 09:38 · PVG 17:38 · LAX 02:38 · JFK 05:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.