R
R
Ranc582017-12-19 23:06:37
Copyright
Ranc58, 2017-12-19 23:06:37

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)

There are 2 instances of this model that have the following values ​​in this field:
1) 2) It is necessary to filter the whole thing according to a certain list. For an example here . The problem is that the output should be all matches, i.e. here it will be [User_1, User_2, User_1]. If I do this: Then I expect to get [User_1, User_2] at the output. I need to get a match for both 37 and 73. {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

2 answer(s)
M
McBernar, 2019-10-10
@McBernar

Pictures you need to buy on deposit/shutter. An average of $1 each. Sounds are more difficult. But, I think, in some unit store there should be such packs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question