Friend
Friend

Reputation: 1346

Sql queries in Django

here is my sql query

SELECT id, name, address, city, state_province, country, website
FROM books_publisher
WHERE name LIKE '%press' and city LIKE '%myn';

as you can see on the above code i have used and for multiple like how to do the same thing in Django? i tried this but did not work

Mplaces.objects.filter(name__startswith='press' and city__startswith=myn)

Upvotes: 0

Views: 73

Answers (2)

catherine
catherine

Reputation: 22808

Mplaces.objects.filter(name__endswith='press', city__endswith='myn')

SQL equivalent:

SELECT ... WHERE name LIKE "%press" and city LIKE "%myn";

Upvotes: 0

Iftikhar Ali Ansari
Iftikhar Ali Ansari

Reputation: 1760

try this:

Mplaces.objects.filter(name__endswith='press', city__endswith=myn)

here ,(comma) means 'and' and | means 'or'

Upvotes: 2

Related Questions