I have a list of postcodes for example:-
postcodes = ['LDN 4DN','MAN 4RF']
The address field has the post code in it, sample address fields are
'1 downing street, London, England, LDN 4DN' '10 the avenues, Manchester, England, MAN 4RF' '20 the Highalnds, Scotland, SCT L40'
Im using
site = SiteData.objects.filter(address__icontains=postcodes[0]))
In a loop to get each site, but that seems a bit lengthy, is it possible to do contains in?
can i run a query to get for example the records for the two postcodes in the list?
Thanks
icontainsis a case insensitive contains, contains on its own is whatinessentially does anywaycontainson its own is whatinessentially does anyway" - err, quite not actually.field__contains='xxx'translates to afield like "%xxx%"(mysql syntax) clause, whilefield__in=("a", "b", "c")translates to a standard SQL in clause, iefield in("a", "b", "c")- which is logically equivalent to(field = 'a' or field = 'b' or field='c').