我有一个应用程序需要登录到单个Drive帐户并使用cron作业自动对文件执行操作.最初,我尝试使用域管理员登录来执行此操作,但是我无法对域管理员进行任何测试,因为您似乎无法将测试服务器与域管理员帐户一起使用,这使得测试我的应用程序有点不可能!
因此,我开始考虑存储arbitray oauth令牌 - 尤其是刷新令牌 - 在初始设置后自动登录此帐户.但是,所有API和文档都假定多个用户手动登录,并且我无法在oauth API中找到允许或记录除当前登录用户之外的任何内容的功能.
如何以可以在测试域上测试代码的方式实现此目的?我可以不用编写自己的oauth库并手动执行oauth请求吗?或者有没有办法让域管理员授权在本地测试服务器上工作?
python google-app-engine python-2.7 google-drive-api google-api-python-client
当.distinct()在一组对象上使用时,相同的值被反复重复,这违背了使用的目的.distinct()
我正在研究的项目的一个例子:
In [5]: Section.objects.filter(module=15).values('section').distinct()
Out[5]: [{'section': '1'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, {'section': '2'}, '...(remaining elements truncated)...']
Run Code Online (Sandbox Code Playgroud)
为什么它返回每个值而不是仅返回不同的值?
供参考,这是我的模型:
class Section(models.Model):
module = models.ForeignKey(Module, on_delete=models.CASCADE)
title = models.CharField(max_length=400)
section = models.CharField(max_length=3)
topic = models.CharField(max_length=3)
subtopic = models.CharField(max_length=3)
subsubtopic = models.CharField(max_length=3)
language = models.CharField(max_length=2)
def __str__(self): …Run Code Online (Sandbox Code Playgroud)