2012-01-09 37 views
0

我有一個要求,我必須加密表中的一些字段。 我正在使用Django 1.3.1和postgres 9.1。我指的是這個應用程序Django的字段: -在Django模型中加密DateField?

https://github.com/svetlyak40wt/django-fields/blob/master/src/django_fields/fields.py

這裏是我的代碼: -

patient_type = EncryptedCharField(max_length=80, choices=CHOICES.PATIENT_TYPES) 
date_of_birth = EncryptedDateField(null=True, blank=True) 
gender = EncryptedCharField(max_length=1024, choices=CHOICES.GENDERS, blank=True) 
contact_phone = EncryptedCharField(max_length=1024, blank=True) 
security_question = models.ForeignKey(SecurityQuestion, null=True, blank=True) 
security_answer = EncryptedCharField(max_length=1024, null=True, blank=True) 

它存儲在加密的形式在一切除了date_of_birth.It數據庫拋出這個錯誤

回溯:在get_response 文件 「/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py」 111響應=回調(請求,* callback_args,** callba ck_kwargs) 文件「/home/user/slave/old_careprep/CPMS-Source/careprep/../careprep/utilities/decorators.py」in _dec 14. return view_func(request,* args,** kwargs) File 「/home/user/slave/old_careprep/CPMS-Source/careprep/../careprep/visit/views.py」in setup 202. patient.save() 文件「/usr/local/lib/python2.7 /dist-packages/django/db/models/base.py「in save 460. self.save_base(using = using,force_insert = force_insert,force_update = force_update) 文件」/usr/local/lib/python2.7/ dist_packages/django/db/models/base.py「in save_base 553. result = manager._insert(values,return_id = update_pk,using = using) 文件」/usr/local/lib/python2.7/dist -insert-packages/django/db/models/manager.py「195. return insert_query(self.model,values,** kwargs) insert_query中的文件「/usr/local/lib/python2.7/dist-packages/django/db/models/query.py」 1436. return query.get_compiler(using = using).execute_sql(return_id) execute_sql中的文件「/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py」 791. cursor = super(SQLInsertCompiler,self).execute_sql(無) 執行文件中的「/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py」 735. cursor.execute( sql,params) 執行文件「/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py」 34. return self.cursor.execute(sql,params) File 「/usr/local/lib/python2.7/dist-packages/django/db/backends/ postgresql_psycopg2/base.py 「在執行 44回self.cursor.execute(查詢參數)

異常類型:DatabaseError在/瀏覽/設置/ 異常值:類型日期無效的輸入語法:」 $ AES $ 55403376ed906e119b0f7779554fbb51「 LINE 1:... L,NULL,'$ AES $ 0452edae035cc33c4084e7b0fb39edd7','$ AES $ 5540 ... ^ 幫助將不勝感激。

感謝

回答

0

我意識到,我是較早使用的DateField,如果我轉換的DateField到CharField,然後應用EncryptedCharField它解決了我的問題