我在Django,A和B中有两个模型.
每个A都有几个B分配给它,并且Bs是有序的,这是用字段B.order_index完成的,该字段从任何A的零向上计数.
我想写一个查询,检查是否有任何A,其中一些B有间隙或重复order_index值.
在SQL中,这可以这样做:
SELECT order_index, RANK() OVER(PARTITION BY a_id ORDER BY order_index ASC) - 1 AS rnk
WHERE rnk = order_index'
Run Code Online (Sandbox Code Playgroud)
但是,当我在Django中尝试使用此代码时:
B.objects.annotate(rank=RawSQL("RANK() OVER(PARTITION BY a_id ORDER BY order_index ASC) - 1", [])).filter(rank=F('order_index'))
Run Code Online (Sandbox Code Playgroud)
我收到一个错误说:
django.db.utils.ProgrammingError: window functions are not allowed in WHERE
LINE 1: ...- 1) AS "rank" FROM "main_b" WHERE (RANK() OVE...
Run Code Online (Sandbox Code Playgroud)
在SQL中,这很容易通过将整个事物包装在子查询中并将Where子句应用于该子查询来修复.我怎样才能在Django中做同样的事情?
我有一个私有 Docker 注册表正在运行。
任何用户都应该能够推送和拉取任何图像。因此,现在我根本没有使用任何用户标识。
但是,用户不应该能够欺骗注册表来覆盖其他用户的图像。
如果用户 A 上传 ourRegistry/myProgram:version_1,那么用户 B 应该无法上传标记为 ourRegistry/myProgram:version_2 的内容。
有没有办法将用户身份验证添加到私有注册表来做到这一点?
此外,注册表是已经拥有自己的注册用户数据库的服务器的一部分。有没有办法同步用户,让用户不必记住两个密码?
authentication user-permissions data-synchronization docker docker-registry
我需要使用 src 属性加载 iframe。我需要附加到查询中的许多附加信息。目前,我只是将所有这些信息放在一个参数中,如下所示:
<iframe src="mywebsite.com/get_iframe?aVeryLongString"></iframe>
Run Code Online (Sandbox Code Playgroud)
但是,aVeryLongString 可能会变得很长。我从服务器收到“414(请求 URI 太大)”错误。
有没有办法在不出现此错误的情况下提出此请求?
注意:iframe 的 url 带有自己的 Content-Security-Policy,所以我不能只使用 srcdoc 而不是 src。除非即使您使用 srcdoc 也有强制 CSP 的方法?
我有一个模型,根据对象是由用户还是由系统创建的,对其名称字段使用不同的验证。
class Symbol(models.Model):
name = models.CharField(_('name'), unique=True, max_length=64)
creator = models.ForeignKey('User', null=True, on_delete=models.CASCADE)
def is_system_internal(self):
"""
whether or not this Symbol belongs to the system rather than having been created by a user
"""
return (self.creator is None)
def clean(self):
"""
ensure that the Symbol's name is valid
"""
if self.is_system_internal():
if not re.match("^_[a-zA-Z0-9\-_]+$", self.name):
raise ValidationError(
_("for system-internal symbols, the name must consist of letters, numbers, dashes (-) and underscores (_) and must begin with an underscore."),
params = …Run Code Online (Sandbox Code Playgroud) django django-validation django-generic-views django-class-based-views