我正在使用Django,我需要使用两个内部联接来执行查询集.
我有三个模型A,B和C,我想在psql中执行如下查询:
select DISTINCT a from A inner join B on B.a_id = A.id inner join C on C.b_id = B.id;
型号:(仅包括相关领域)
class A(models.Model):
id = models.IntegerField(primary_key=True)
class B(models.Model):
id = models.IntegerField(primary_key=True)
a = models.ForeignKey(A, null=True, blank=True,on_delete=models.SET_NULL)
class C(models.Model):
b = models.ForeignKey(B, null=True, on_delete=models.SET_NULL)
Run Code Online (Sandbox Code Playgroud)
因此,C中的所有内容都链接回B中的一个内容,而B中的所有内容都链接回A中的一个内容.我想尝试获取A中具有C语言内容的所有不同元素.
如何使用django queryset执行此操作?谢谢.
我正在尝试让我的程序识别出使用NSCollectionView进行双击.我尝试过这个指南:http://www.springenwerk.com/2009/12/double-click-and-nscollectionview.html但是当我这样做时,没有任何反应,因为IconViewBox中的委托是null:
h文件:
@interface IconViewBox : NSBox
{
IBOutlet id delegate;
}
@end
Run Code Online (Sandbox Code Playgroud)
m文件:
@implementation IconViewBox
-(void)mouseDown:(NSEvent *)theEvent {
[super mouseDown:theEvent];
// check for click count above one, which we assume means it's a double click
if([theEvent clickCount] > 1) {
NSLog(@"double click!");
if(delegate && [delegate respondsToSelector:@selector(doubleClick:)]) {
NSLog(@"Runs through here");
[delegate performSelector:@selector(doubleClick:) withObject:self];
}
}
}
Run Code Online (Sandbox Code Playgroud)
第二个NSLog永远不会被打印,因为委托是空的.我已经连接了我的nib文件中的所有内容并按照说明操作.有谁知道为什么或替代为什么这样做?
我有一个文件A.js,我有一个模块级变量activeCount.我使用module.exports导出它.我有一个测试文件testA.js,我检查的值activeCount.
但是似乎我做的修改A.js,以activeCount不被看见testA.js.我想这可能是因为当我改变时activeCount,它会导致module.exports.activeCount并activeCount指向不同的对象.我是否正确分析了这一点,如果是这样,我如何在activeCount不创建新对象的情况下更改值?
A.js
var activeCount = 0;
...
function reset() {
activeCount = 0;
}
function A() {
...
}
module.exports = A;
module.exports.activeCount = activeCount;
module.exports.reset = reset;
A.prototype.addFunction(...) {
...
activeCount++;
...
}
Run Code Online (Sandbox Code Playgroud)
testA.js
var A = require('A');
test('test1', function (assert) {
var a = new A();
a.addFunction(...);
console.log(A.activeCount); // prints 0 instead of 1
}); …Run Code Online (Sandbox Code Playgroud)