Skip to content

harikitech/django-lookup-extensions

Repository files navigation

Django lookup extensions

https://travis-ci.org/uncovertruth/django-lookup-extensions.svg?branch=master https://api.codacy.com/project/badge/Grade/d5a64517be0d49b6bf2f41c11df77730 https://codebeat.co/badges/20da13a3-e873-412a-89b1-1a02bba47a23 https://www.codefactor.io/repository/github/uncovertruth/django-lookup-extensions/badge Documentation Status Updates Python 3

Django lookup extensions use NOT query.

Installation

To install Django lookup extensions, run this command in your terminal:

$ pip install django-lookup-extensions

This is the preferred method to install Django lookup extensions, as it will always install the most recent stable release.

If you don't have pip installed, this Python installation guide can guide you through the process.

Usage

Setup

Add 'lookup_extensions' to your INSTALLED_APPS setting.:

INSTALLED_APPS = [
    ...
    'lookup_extensions',
    ...
]

AppConfig.ready imports lookups and register them using django.db.models.fields.Field.register_lookup.

Making queries

Use lookup like Django standard lookups.

ModelA.objects.filter(name__neexact='test name')

Supported lookup types

Negaetes

neexact is negate exact, neiexact is negate iexact, others are similar.

  • neexact
  • neiexact
  • necontains
  • neicontains
  • nestartswith
  • neendswith
  • neistartswith
  • neiendswith
  • neregex
  • neiregex

Complement

  • complement

Extra regexes

These regex lookups support metacharacters \d, \D, w, \W, \s, \S.

MySQL, PostgreSQL and Redshift also support \<, \>.

Prefix follows the previous section.

  • exregex
  • exiregex
  • neexregex
  • neexiregex

Supported vendor types

  • MySQL
  • PostgreSQL
  • sqlite
    • lookups using LIKE aren't case sensitive.
      • necontains
      • nestartswith
      • neendswith
  • Redshift

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.