Answer the question
In order to leave comments, you need to log in
How to filter an ArrayField by all possible elements?
Good afternoon!
There is a model that has an ArrayField roles
:
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(_('Username'), max_length=50, blank=True)
email = models.CharField(_('Email'), null=True, max_length=200)
first_name = models.CharField(_('First name'), null=True, max_length=200)
last_name = models.CharField(_('Last name'), null=True, max_length=200)
middle_name = models.CharField(_('Middle name'), null=True, max_length=200)
roles = ArrayField(models.IntegerField(_('Roles')), blank=True, default=list)
{37, 73}
{37}
[37, 73]
User.objects.filter(roles__overlap=[37, 73])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question