0

I have this Postgresql query:

select a.code from accounts a where a.code like '0077-7575%' or '0077-7575' like a.code||'%'

At django I am trying to do this:

q = Accounts.objects.filter(Q(code__startswith='0077-7575') | Q('0077-7575'__startswith=code))

The thing is I don't know and can't find a way to translate '0077-7575' like a.code||'%' into django since a.code is the field name... How can I solve this?

assembler
  • 3,098
  • 12
  • 43
  • 84

1 Answers1

1

If i am guessing correctly (that you are trying to check that your field is contained inside '0077-7575', you could try something written in this answer.

Basically you would have to do smth like:

Accounts.objects \ 
  .annotate(querystring=Value('0077-7575', output_field=CharField())) \ 
  .filter(querystring__contains=F('code'))