[Django]-Django: how to filter on extra column?

2👍

The as the correct marked answer, of the similar question, mentions; it is not possible to use a filter (because filter() only inspects model definitions). It suggest to use another extra, containing a where clause.

So something like;

Foo.objects\
    .extra(select={'extra_column':'SELECT ...'})\
    .extra(where=["extra_column = %s"], params=[value])

As of Django 1.7 you can work with lookups:
https://docs.djangoproject.com/en/1.7/howto/custom-lookups/

Leave a comment