How django model was filtered by bit

0

all,

I want to use an integer to store the user verification status. For example: There are following information needs to be verified: email address, citizen id, drive license. the definition as follows: 0x00000001 means user submitted email address. 0x00000002 means user's email has been verified and passed. 0x00000005 means user's email address is not correct.

0x00000010 means user submitted citizen id. 0x00000020 means user's citizen id has been verified and passed. 0x00000050 means user's citizen id is not correct.

0x00000100 means user submitted drive license id. 0x00000200 means user's drive license id has been verified and passed. 0x00000500 means user's drive license id is not correct.

I want to filter the user's email has been verified. how can I filter it by django model. What I want to get is status & 0x0000000f == 2.

Thanks a lot.

django
asked on Stack Overflow Dec 19, 2013 by user758479

1 Answer

0

I would not try to use this approach for storing in your database. Why not simply go for three SmallIntegerFields like status_email, status_citizen and status_drivelicense which can hold the values 0 (submitted), 1 (verified) and -1 (incorrect)? That is a lot easier for your application logic and also for filtering in the database.

Can you explain the reason why you want to encode the information the way you do it?

answered on Stack Overflow Dec 19, 2013 by mawimawi

User contributions licensed under CC BY-SA 3.0