我正在做这个教程,并且陷入了标记部分.基本上我有文章可以有一个标签列表.由于一篇文章可以有多个标签,反之亦然,因此还有一个额外的taggings
模型,通过该模型建立这种关联.以下是模型:
class Article < ActiveRecord::Base
has_many :comments
has_many :taggings
has_many :tags, through: :taggings
end
class Tag < ActiveRecord::Base
has_many :taggings
has_many :articles, through: :taggings
end
class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :article
end
Run Code Online (Sandbox Code Playgroud)
和迁移:
def change
create_table :articles do |t|
t.string :title
t.text :body
t.timestamps
end
create_table :tags do |t|
t.string :name
t.timestamps
end
create_table :taggings do |t|
t.references :tag, index: true
t.references :article, index: true
t.timestamps
end
Run Code Online (Sandbox Code Playgroud)
还有article_controller
(其中包括):
def create
@article = …
Run Code Online (Sandbox Code Playgroud) 2016.1.2版本的PyCharm似乎不再自动完成对Django模型的查询.例如,Foo.objects.filter(some-field-lookup)
过滤器方法没有得到自动完成(或任何其他方法),并且字段查找参数也没有得到自动完成,这两个都在PyCharm版本5中有效.是否有其他人有此问题?这是预期的行为吗?是否有一些需要打开的设置?
编辑:重新启动或使缓存无效并重新启动对此没有任何影响