这可能是侮辱性的简单而且值得Nelson Muntz笑,但我有一个真正的脑死亡时刻试图在不同的模型关系中建立多对多的联系.
我有以下型号(简化为您的享受!):
class Document(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey(User, blank=True)
content = models.TextField(blank=True)
private = models.BooleanField(default=False)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
friends = models.ManyToManyField(User, symmetrical=False,
related_name='user_friends')
ignored = models.ManyToManyField(User, symmetrical=False,
related_name='user_ignored')
Run Code Online (Sandbox Code Playgroud)
成像以下用户:
搜索文档的用户应该生成以下内容:
基本上,我正在精神上努力找出过滤器以返回我上面描述的查询集.有人有任何想法吗?
编辑
感谢Ferdinands的回答,我能够通过他给我的开始坚持到我想要的东西.首先,我们希望得到一个与我结识的人员名单,这是通过多对多关系进行反向查询:
friendly_authors = self.user.user_friends.all()
Run Code Online (Sandbox Code Playgroud)
得到我忽略的所有人:
my_ignored = UserProfile.objects.get(user=self.user).ignored.all()
Run Code Online (Sandbox Code Playgroud)
获取我可以查看的文档列表 - 可以查看,使用或编写文档的文档,这些文档可能是我的朋友,但我没有忽略过:
docs = Document.objects.filter(
(Q(viewable=True) | Q(author=self.user) | Q(author__in=friendly_authors))
& ~Q(author__in=my_ignored)
)
Run Code Online (Sandbox Code Playgroud) lock(dictionaryX)
{
dictionaryX.TryGetValue(key, out value);
}
Run Code Online (Sandbox Code Playgroud)
在查找字典时是否需要锁定?
程序是多线程的,并且在向dict添加键/值时.dict被锁定了.
我在C#中使用Lookup类作为我的主要数据容器,供用户从两个Checked List框中选择值.
Lookup类比使用类Dictionary更容易使用,但是我找不到用于删除和向查找类添加值的方法.
我想过使用where和union,但我似乎无法正确使用它.
提前致谢.
我有一个有签名的词典:Dictionary<int, List<string>>
.我想将它转换为带签名的Lookup : Lookup<int, string>
.
我试过了:
Lookup<int, string> loginGroups = mapADToRole.ToLookup(ad => ad.Value, ad => ad.Key);
Run Code Online (Sandbox Code Playgroud)
但这并不是那么好用.
我在哪里可以找到导入我的数据库的表格中的美国国家列表?
SQL是理想的,否则CSV或其他平面文件格式是好的.
编辑:完成两个字母的州代码
现在我正在循环跟踪我的索引
index = 0
for entry in longList:
if entry == 'foo':
print index
index += 1
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
我有三个列表,如下所示:
Initiatives
-----------
Initiative (single line text)
Themes
------
Theme (single line text)
Initiative (Lookup from Initiatives:Initiative)
Points (number)
Features
--------
Feature (single line text)
Theme (Lookup from Themes:Theme)
Points (Lookup from Themes:Points) # <- This here works fine.
Initiative (Lookup from Themes:Initiative) # <- This here is busted and can't do.
Run Code Online (Sandbox Code Playgroud)
看到最后一行...... Initiative (Lookup from Themes:Initiative)
< - 这就是我试图获得与主题相关的主动权.我尝试了很多不同的东西,只是无法弄清楚如何做到这一点.
它甚至可能吗?如果是这样,怎么样?
FWIW - 我使用的是SharePoint 2010,可以使用从Web工具到SharePoint Designer的任何内容.我是SharePoint 站点上的管理员,但不是服务器上的管理员.
如何使用字符向量变量作为参数动态查找多个字段并通过引用添加.在下面的情况下,我想查找两列并删除i.
它们中的前缀.当然,他们可以覆盖具有相同名称的现有列.
library(data.table)
set.seed(1)
ID <- data.table(id = 1:3, meta = rep(1,3), key = "id")
JN <- data.table(idd = sample(ID$id, 3, FALSE), value = sample(letters, 3, FALSE), meta = rep(1,3), key = "idd")
select <- c("value","meta") # my fields to lookup
j.lkp <- call(":=", select, lapply(paste0("i.",select), as.symbol))
j.lkp
# `:=`(c("value", "meta"), list(i.value, i.meta))
ID[JN, eval(j.lkp)]
# Error in eval(expr, envir, enclos) : could not find function "i.value"
ID[JN, `:=`(c("value", "meta"), list(i.value, i.meta))]
# id meta value
# …
Run Code Online (Sandbox Code Playgroud) 我有一个分为单词的名称(字符串)列表.有800万个名字,每个名字最多包含20个单词(代币).唯一令牌的数量是220万.我需要一种有效的方法来查找包含查询中至少一个单词的所有名称(最多可包含20个单词,但通常只包含几个单词).
我目前的方法使用Python Pandas,看起来像这样(后面提到original
):
>>> df = pd.DataFrame([['foo', 'bar', 'joe'],
['foo'],
['bar', 'joe'],
['zoo']],
index=['id1', 'id2', 'id3', 'id4'])
>>> df.index.rename('id', inplace=True) # btw, is there a way to include this into prev line?
>>> print df
0 1 2
id
id1 foo bar joe
id2 foo None None
id3 bar joe None
id4 zoo None None
def filter_by_tokens(df, tokens):
# search within each column and then concatenate and dedup results
results = [df.loc[lambda df: df[i].isin(tokens)] for i in range(df.shape[1])] …
Run Code Online (Sandbox Code Playgroud) 我的APP通过比较iTunes查找API返回的本地版本和远程版本来检查更新.但新版本发布后,API仍会返回旧版本.
https://itunes.apple.com/us/lookup?bundleId=com.xxx.xxxx
如果我通过浏览器请求,此API返回新版本(4.9),但在APP中返回旧版本(4.8.1).
有人帮忙吗?谢谢.
- (void)updateAppInfo
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//first check iTunes
NSString *iTunesServiceURL = [NSString stringWithFormat:@"https://itunes.apple.com/us/lookup"];
iTunesServiceURL = [iTunesServiceURL stringByAppendingFormat:@"?bundleId=%@", [[NSBundle mainBundle] bundleIdentifier]];
NSLog(@"iRate is checking %@ to retrieve the App Store details...", iTunesServiceURL);
NSError *error = nil;
NSURLResponse *response = nil;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:iTunesServiceURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode;
if (data && statusCode == 200)
{
//in case error is garbage...
error = nil;
id …
Run Code Online (Sandbox Code Playgroud) lookup ×10
c# ×2
dictionary ×2
list ×2
python ×2
.net ×1
c#-3.0 ×1
csv ×1
data.table ×1
django ×1
dynamic ×1
hashtable ×1
indexing ×1
ios ×1
itunes-store ×1
linq ×1
locking ×1
many-to-many ×1
pandas ×1
performance ×1
r ×1
relationship ×1
sharepoint ×1
sql ×1