Python django.db.models.Lookup() Examples

The following are 2 code examples for showing how to use django.db.models.Lookup(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.db.models , or try the search function .

Example 1
Project: djongo   Author: nesdis   File: tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_custom_exact_lookup_none_rhs(self):
        """
        __exact=None is transformed to __isnull=True if a custom lookup class
        with lookup_name != 'exact' is registered as the `exact` lookup.
        """
        class CustomExactLookup(models.Lookup):
            lookup_name = 'somecustomlookup'

        field = Author._meta.get_field('birthdate')
        OldExactLookup = field.get_lookup('exact')
        author = Author.objects.create(name='author', birthdate=None)
        try:
            type(field).register_lookup(Exactly, 'exact')
            self.assertEqual(Author.objects.get(birthdate__exact=None), author)
        finally:
            type(field).register_lookup(OldExactLookup, 'exact') 
Example 2
Project: djongo   Author: nesdis   File: tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_custom_exact_lookup_none_rhs(self):
        """
        __exact=None is transformed to __isnull=True if a custom lookup class
        with lookup_name != 'exact' is registered as the `exact` lookup.
        """
        class CustomExactLookup(models.Lookup):
            lookup_name = 'somecustomlookup'

        field = Author._meta.get_field('birthdate')
        OldExactLookup = field.get_lookup('exact')
        author = Author.objects.create(name='author', birthdate=None)
        try:
            type(field).register_lookup(Exactly, 'exact')
            self.assertEqual(Author.objects.get(birthdate__exact=None), author)
        finally:
            type(field).register_lookup(OldExactLookup, 'exact')