作为其中一项要求的一部分,我们将覆盖自定义Queryset中的Update方法.
示例代码如下.
from django.db.models.query import QuerySet
class PollQuerySet(QuerySet):
def update(self, *args, **kwargs):
# Some Business Logic
# Call super to continue the flow -- from below line we are unable to invoke super
super(self, kwargs)
class Question(models.Model):
objects = PollQuerySet.as_manager()
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
Run Code Online (Sandbox Code Playgroud)
它无法从自定义查询集调用基本Queryset中的更新.
/ polls /中的TypeError必须是type,而不是PollQuerySet
非常感谢任何解决方案.
我们正在尝试在 ruby 中实现 SHA256 Base64 哈希,它没有像在 C# 中那样返回预期的结果。
下面是我们的 C# 示例代码。
public static string HashSHA256ToBase64(string phrase)
{
if (phrase == null)
return null;
var encoder = new UTF8Encoding();
var sha256Hasher = new SHA256CryptoServiceProvider();
var hashedDataBytes = sha256Hasher.ComputeHash(encoder.GetBytes(phrase));
return Convert.ToBase64String(hashedDataBytes);
}
Run Code Online (Sandbox Code Playgroud)
为此,我们需要用 ruby 编写等效的代码。为此,我们正在尝试如下。
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), "", phrase))
Run Code Online (Sandbox Code Playgroud)
它提供的结果与 C# 不同。
测试短语:V2dcZBpzzglD1ynW5ZAyFocs9wtpR624wlla9gujw0I=RquZ/QzazPM=
预期结果:utXwt733s9FmiSM69o2zGOm0IT42FjthbB0oquIuPak=
有人可以用等效的 ruby 代码帮助我解决这个问题吗