Django filter __contains returns no value on a list while __in does

am essentially trying to perform a select * from xyxtable where col like '%value%' on a list of alphanumeric values from another dataframe column(prev_df['VendorPartNumber]. I thought the filter __contains= should do the trick. but this returns nothing

product_df=pd.DataFrame(Product.objects.filter(legacy_productid__contains=prev_df['VendorPartNumber']).values('id','legacy_productid'))

however using the __in to filter works (just that the result is not what I want since __in tests for equality)

product_df=pd.DataFrame(Product.objects.filter(legacy_productid__in=prev_df['VendorPartNumber']).values('id','legacy_productid'))

I tried a couple of things such as

     product_df= Product.objects.all()
        for search_term in perv_df['VendorPartNumber']:
            product_df = product_df.filter(legacy_productid__contains=search_term)

or

        product_df=pd.DataFrame(Product.objects.filter(reduce(operator.and_, (Q(legacy_productid__contains=x) for x in prev_df['VendorPartNumber']))).values('id','legacy_productid'))

what am I missing?

I assume you want to retrieve the id of legacy_product.

In that case you have to do legacy_product_id__contains='foobar'.

Back to Top