[Answered ]-Django: simulate a flags Field using BInaryField

1👍

Well, in django common approach for building such functionalities is using MultipleChoiceField. It presumes that data is stored in the related table, which, I believe, is not very what you want.

The second opportunity is to use ArrayField which also isn’t suitable for you since you don’t want your solution to be limited to PostgreSQL.

If you’re going to do this quickly and straightforward, you might use JSONField and store the string or numeric IDs of your Choices. But if you are accustomed to C++, you’re not gonna like it this way 🙂

JSONField is supported on MariaDB 10.2.7+, MySQL 5.7.8+, Oracle, PostgreSQL, and SQLite (with the JSON1 extension enabled).

If so, you should look at SmallIntegerField, it’s stored as 16-bit signed int and use getter-setter approach to maintain it, like this. The idea of implementation of the methods you suggested is right in general.

Good luck 🙂

Leave a comment