Jared Mackey
Jared Mackey

Reputation: 4158

Postgresql Prefix in django orm

How could I go about utilizing the Postgres Prefix Plugin within django? Is there a way to just append an additional WHERE clause to the queries that django runs without going into raw SQL?

Maybe something like this?

Model.objects.filter(field1=2, field2__in=[1,2,3]).where("prefix @> '0123456789'")

Upvotes: 1

Views: 154

Answers (1)

stellasia
stellasia

Reputation: 5622

Yes it is possible, this is the extra method on QuerySet. Something like this should do the trick:

 Model.objects.filter(...).extra(where=["prefix @> '0123456789'"])

Upvotes: 2

Related Questions