Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django filter() lookup type documentation

I looked on Django's documentation and Googled every varation of the phrase but I cannot find any documentation that exactly describes the behaviour of lookuptypes.

app.objects.filter(column__lookuptype=criteria)

I have found documentation on which lookuptypes I can use but not what they do or how to use them. For example, I have no bloody clue what __gte does, but I cannot find good documentation on what it does either.

Is there documentation that I overlooked?

Any pointers in the right direction would be greatly appreciated. Thanks!

like image 594
RomaH Avatar asked Jun 03 '12 19:06

RomaH


People also ask

How does Django filter work?

Django-filter is a generic, reusable application to alleviate writing some of the more mundane bits of view code. Specifically, it allows users to filter down a queryset based on a model's fields, displaying the form to let them do this.

What is lookups in Django?

A Lookup is a generic class to implement lookups. A lookup is a query expression with a left-hand side, lhs ; a right-hand side, rhs ; and a lookup_name that is used to produce a boolean comparison between lhs and rhs such as lhs in rhs or lhs > rhs .

What is a QuerySet?

A QuerySet represents a collection of objects from your database. It can have zero, one or many filters. Filters narrow down the query results based on the given parameters. In SQL terms, a QuerySet equates to a SELECT statement, and a filter is a limiting clause such as WHERE or LIMIT .


1 Answers

They are called "field lookups" in Django. Field lookups have pretty comprehensive documentation: https://docs.djangoproject.com/en/dev/ref/models/querysets/#id4

These are pretty well documented:

  • exact
  • iexact
  • contains
  • icontains
  • in
  • gt
  • gte
  • lt
  • lte
  • startswith
  • istartswith
  • endswith
  • iendswith
  • range
  • year
  • month
  • day
  • week_day
  • isnull
  • search
  • regex
  • iregex
like image 67
Tadeck Avatar answered Sep 25 '22 11:09

Tadeck