How to generate HASH for Django model

后端 未结 2 1960
萌比男神i
萌比男神i 2021-01-04 20:59

I am trying to generate unique HASH values for my Django models of 10 digit i have tried these methods but i am getting this error

return Database.Cursor.ex         


        
2条回答
  •  臣服心动
    2021-01-04 21:28

    Don't call the _createHash() function in your field, but just pass the reference to the callable in your model, e.g.

    hash_1 = models.CharField(max_length=10,default=_createHash,unique=True)
    

    As Lennart Regebro mentioned in his answer, you'll get the same value for each time you start the server in your attempt.

    The Django docs say this about it:

    Field.default

    The default value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.

提交回复
热议问题