1
基本上,我需要使用用戶的密碼哈希通過自定義模型字段來加密一些數據。看看我在這裏使用的代碼片段:Django Encryption。如何將用戶模型傳遞到表單域(django)?
我嘗試這樣做:
class MyClass(models.Model): owner = models.ForeignKey(User) product_id = EncryptedCharField(max_length=255, user_field=owner) ................................................................................. def formfield(self, **kwargs): defaults = {'max_length': self.max_length, 'user_field': self.user_field} defaults.update(kwargs) return super(EncryptedCharField, self).formfield(**defaults))
但是,當我嘗試使用user_field,我得到一個ForeignKey實例(當然!):
user_field = kwargs.get('user_field') cipher = user_field.password[:32]
任何幫助表示讚賞!
更優雅「Python化」的方式首先,感謝您的回覆!希望我能想出類似這樣的東西。但是,關於如何用信號完成這個任務,你有沒有一個基本的例子?作爲一個整體,我對信號的知識非常有限...... – Bryan 2009-11-16 18:26:57
增加了信號處理程序,歡呼聲。 – Evgeny 2009-11-16 18:44:34
謝謝!哇,我真的很感動。我一定會在稍後再說。再次感謝! – Bryan 2009-11-16 18:53:11