0

In my case customer filed are array filed

customer = ArrayField(models.TextField(),default=[])

my model look like

id customer
1 {1,2,3}
2 {4,2,5}
3 {1,8,9}

i want to filter my model by {5,8} output will be 2th ,3th row

1

1 Answer 1

2

You can use overlap like this:

customer_ids = MyModel.objects.filter(
     customer__overlap=[5, 8]
).values_list('id', flat=True)
# do something with customer_ids

But using id to determine row number is not right because if you delete an item having an id as 3 and then after that insert a new item then that new item will be given an id of 4. So row number of last row will give you 4th row which is wrong.

You can get row number like this:

row_numbers = [index for index, customer_id in enumerate(customer_ids)]  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.