简体   繁体   English

PyCharm Django ORM不显示django.db.models中的Manager自动完成子级

[英]PyCharm Django ORM does not display Manager autocomplete children from django.db.models

So I'm frustrated by the autocomplete of Django PyCharm. 因此,我对Django PyCharm的自动完成感到沮丧。 It does not improved SQL completion and other enhancements. 它没有改善SQL的完成和其他增强功能。

from django.db import models

import datetime from django.utils import timezone 从django.utils导入时区导入datetime

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField(max_length=200)

    def __str__(self):              # __unicode__ on Python 2
        return self.question_text

    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) < self.pub_date <= now
        #return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

    was_published_recently.admin_order_field = 'pub_date'
    was_published_recently.boolean = True
    was_published_recently.short_description = 'Published recently?'


class Choice(models.Model):
    question = models.ForeignKey(Question)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

    def __str__(self):              # __unicode__ on Python 2
        return self.choice_text

for example if I try using Question object from the model and look for objects (Question.objects) and typing dot after objects it should give me the suggestions of "all, first, last, etc." 例如,如果我尝试从模型中使用Question对象并查找对象(Question.objects),然后在对象后键入点,则应该给我“所有,第一个,最后一个等”的建议。 but it does not have any suggestions. 但它没有任何建议。 It's hard to learn without it, any suggestions how could I fix this? 没有它很难学习,有什么建议我该如何解决? I have installed latest interpreters like IPython, SQLAlchemy and more. 我已经安装了最新的解释器,例如IPython,SQLAlchemy等。 In addition to that I have "Collect run-time types information for code insight" enabled. 除此之外,我还启用了“收集运行时类型信息以进行代码分析”。

Unfortunatly PyCharm has had this issue for a very long time and is likely never going to fix it. 不幸的是,PyCharm已经有很长时间了,并且可能永远无法修复。

I find myself having to do 我发现自己必须做

""":type varname: ObjectType"""

or using isinstance(..) 或使用isinstance(..)

to get autocomplete to work well. 获得自动完成功能以使其正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM